You can keep Records in Dynamic arrays and TLists...
Depends what your are wanting to do and wanting to do with the data structure (Record or Object).
 
Regards
Paul McKenzie
Analyst Programmer
SMSS ltd.
 
----- Original Message -----
Sent: Tuesday, February 25, 2003 11:40 AM
Subject: RE: Re: [DUG]: Using TList

What would be the best way to hold an enumeration of record type?

 

Should I declare them as a Tobject instead of record and then keep them in a TList?

 

Jay

 

-----Original Message-----
From: Todd Martin [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 25 February 2003 11:24 a.m.
To: Multiple recipients of list delphi
Subject: Re: [DUG]: Using TList

 

Looks okay to me. Although you don't really need the Remove() and IndexOf() methods, as these just call the TList methods anyway.

 

Also, GetPic() could just call the inherited Get() method and cast the result as TPicture. In your GetPic() and PutPic() methods there's no need to cast with the Pointer type as TPicture is just a pointer anyway.

 

eg.

procedure TPics.PutPic(index: Integer; Pic: TPicture);

begin

  inherited Put(index, Pic);

end;

 

function TPics.GetPic(index: Integer): TPicture;

begin

  result := TPicture(inherited Get(index));

end;

 

Personally, I think the Put() method is very scary, since it can easily lead to memory leaks when the list holds the only pointer to an object. In other words, I usually make the Items property read only.

 

Cheers,

Todd.

----- Original Message -----

From: Jason Coley

Sent: Tuesday, 25 February 2003 10:50

Subject: [DUG]: Using TList

 

Is the below declaration of a TList that holds TPictures?

 

 

 

  TPics = class(TList)

  private

    procedure PutPic(index: Integer; Pic: TPicture);

    function GetPic(index: Integer): TPicture;

  public

    property Items[Index: Integer]: TPicture read GetPic write PutPic; default;

    function Add(Pic: TPicture): integer;

    function Remove(Pic: TPicture): integer;

    function IndexOf(Pic: TPicture): Integer;

    procedure Insert(Index: Integer; Pic: TPicture);

  end;

 

 

implementation

 

 

procedure TPics.PutPic(index: Integer; Pic: TPicture);

begin

  inherited Put(index, pointer(Pic));

end;

 

function TPics.GetPic(index: Integer): TPicture;

begin

  result := TPicture(pointer(inherited items[index]));

end;

 

function TPics.Add(Pic: TPicture): Integer;

begin

  result := inherited add(Pic);

end;

 

function TPics.Remove(Pic: TPicture): Integer;

begin

  result := inherited remove(Pic);

end;

 

function TPics.IndexOf(Pic: TPicture): Integer;

begin

  result := inherited indexOf(Pic);

end;

 

procedure TPics.Insert(Index: Integer; Pic: TPicture);

begin

  inherited insert(index, Pic);

end;

 

thanks

Jay

Reply via email to