Whether or not it's an ideal way of achieving this I'll suggest what I've done in the past. I've created a TList and then added objects to this list. i.e.
MyList.Add(Query1);
MyList.Add(Query2);
etc.
In order to use the objects in this list as their appropriate type (i.e. TQuery) I use something like 'TQuery(MyList[x]).Active := True;'.
Hope that this helps.
Steve
I'm assuming you haven't set the size of your object array. Since you have declared it as a dynamic array, before you can use it, you need to set the size of the array. For example :
var
MyObjectA : array of MyObject;
begin
SetLength(MyObjectA, 9);
MyObjectA[0] := MyObject.Create;
end;
Thanks all,
I have a variable # of objects and would like to use a TLIST but I am missing how to Create an instance of an object dynamically. I want to use
New(MyObject)
and assign it to a reference and then to the TLIST. I can declare the instances of the object like:
MyObject1,MyObject2 : TMyObject;
and Create them but I am limited to the 2. Is there a way around this? There must be but I am not getting it at the moment.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.