Einzelnen Beitrag anzeigen

WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#1

Stored classes identified by integer - how to get type base on number?

  Alt 28. Nov 2011, 17:54
Delphi-Version: 2010
I'm storing in stream classes fields values (each class has SaveToStream/LoadFrom strem methods). Now for example if I need load from file these classes to object I'm doing:

Delphi-Quellcode:
case AType of
  0: TFirstClass.Create.LoadFromStream;
  1: TAnotherClass.Create.LoadFromStream;
  // ........
end;
This was good (but yes - lame) when was small set of classes. Now I have many ones and this method is also annoying when need to update.

Is possible map number to class type:

Delphi-Quellcode:
function GetType(AType: Int32): TBaseClass;
begin
  // ?????????????????
end;


and do

GetType(AType).Create.LoadFromStream ;

  Mit Zitat antworten Zitat