Einzelnen Beitrag anzeigen

barf00s
(Gast)

n/a Beiträge
 
#14

Re: Zugriff auf Variablen im Record wie FindComponent

  Alt 8. Jul 2005, 13:45
BESSER wäres ja noch wenn du von "record" auf "class" umstellst, dann brauchst dieses PRecorc() gefricke nich...

Delphi-Quellcode:
uses
  Contnrs; // TObjectList

type
  TEintrag = class
  private
    FName: string;
    FVorname: string;
    FStrasse: string;
    FPlz: integer;
    procedure SetName(const Value: string);
  public
    property Name: string read FName write SetName;
    // ...
  end;

  TEintraege = class(TObjectList)
  private
    function GetItems(Index: integer): TEintrag;
    procedure SetItems(Index: integer; const Value: TEintrag);
  public
    function FindByName(const Name: string): TEintrag;
    proeprty Items[Index: itneger]: TEintrag read GetItems write SetItems; default;
  end;

implementation

function TEintraege.GetItems(Index: integer): TEintrag;
begin
  Result := TEintrag(inherited Items[Index]);
end;

procedure TEintraege.SetItems(Index: integer; const Value: TEintrag);
begin
  inherited Items[Index] := Value;
end;

function TEintraege.FindByName(const Name: string): TEintrag;
var
  iIndex: integer;

begin
  Result := nil;
  for iIndex := 0 to Count - 1 do begin
    if Items[iIndex].Name = Name then begin
      Result := Items[iIndex];
      Exit;
  end;
end;
  Mit Zitat antworten Zitat