1

I'm not sure if this is actually possible with RTTI, but I though I would ask.

I have a global unit which just holds a number of var pick lists in the form of TStringList. Via a database record returning a string, can I use RTTI to find the correct string list in the unit by "name" and return it?

function GetStringListFromUnitByName(aUnit, aName: String): TStringList;
begin

end;

Would it help if all the stringlists were stored as public variables in a generic class?

TMyPickLists = class
public
  FList1: TStringList;
  FList2: TStringList;
end;
mikelittlewood
  • 223
  • 4
  • 15

1 Answers1

3

Global variables cannot be enumerated using RTTI. You would need to use variables of a class as you suggest. These could be instance variables, or class variables.

Personally though, I don't see the point of using RTTI here. If it were me, I would create a dictionary and add the lists to the dictionary during initialization:

var
  PickLists: TDictionary<string, TStringList>;
....
PickLists := TDictionary<string, TStringList>.Create;
PickLists.Add('List1', List1);
// etc.
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490