At 07:52 12/03/2005, you wrote:
Tim wrote:Can anyone refer me to a good article about working with TList objects?
What kinds of things would you like such an article to cover? I ask because I'm thinking of writing one.
-- Rob
_______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi
I have several places in the application I am working on where I create a new object and add the object to the items property of a TList object.
When I want to access the created object's parameters, I find that my code looks "clunky", and was wondering if there was not a more elegant and efficient way of doing it.
For example :
var MyObject : TMyObject
begin
MyObject := TMyObject.Create(Self);
MyObject.FieldOne := 'AValue';
MyObject.FieldTwo := 1;
AList.Items.Add(MyObject);
end;Then, sometime later in the code, I want to access one of the objects' fields. So the only way I have found of doing it is as follows :
var
TempObject : TMyObject;
i : integer;
begin for i := 0 to AList.Count do
begin
TempObject := AList.Items[i];
if TempObject.FieldOne = SomeValue then
begin
dosomething;
end;
end;I understand that TList is a list of pointers. What I cannot understand is why I can't do something like\
for i := 0 to AList.Count do
begin
if AList.Items[i]^ is TMyObject then
with AList.Items[i]^ as TMyObject doetc etc etc.
In other words, I suppose my question is "If TList is a list of TPointer, the how do I dereference the pointer to access the object? Is accessing the Items property the only way to do it?"
Thanks in advance
Tim
_______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

