Thema: Delphi Assoziative Arrays

Einzelnen Beitrag anzeigen

Benutzerbild von Jens Schumann
Jens Schumann

Registriert seit: 27. Apr 2003
Ort: Bad Honnef
1.644 Beiträge
 
Delphi 2009 Professional
 
#3

Re: Assoziative Arrays

  Alt 1. Mai 2004, 11:15
Hallo,
grundsätzlich würde ich es so lösen
Delphi-Quellcode:
unit Unit2;

interface

uses SysUtils, classes;

Type

  TArrayItem = class(TObject)
  private
    FName: String;
  public
    property Name : String read FName write FName;
  end;

  TArrayItems = class(TList)
  private
    function GetArrayItem(Name: String): TArrayItem;
  public
    function Add(const Itemname : String) : TArrayItem;
    property ArrayItems[Name : String] : TArrayItem read GetArrayItem;
  end;

implementation

{ TArrayItems }

function TArrayItems.Add(const Itemname: String): TArrayItem;
begin
  Result:=TArrayItem.Create;
  inherited Add(Result);
end;

function TArrayItems.GetArrayItem(Name: String): TArrayItem;
var
  iCnt : Integer;
begin
  Result:=Nil;
  For iCnt:=0 to Count-1 do
    begin
    If AnsiUpperCase(TArrayItem(Items[iCnt]).Name)=AnsiUpperCase(Name) then
      begin
      Result:=Items[iCnt];
      Exit;
      end;
    end;
end;

end.
I come from outer space to save the human race
  Mit Zitat antworten Zitat