Can you create a generic that is based on a class that can stream itself using rtti regardles of its structure ?
Something like Type TFundamentalClass = Class(TObject) Public Function GetProperty(Propertyname : String): Variant; Procedure SetProperty(PropertyName : String; Value : Variant); Procedure WritePropertiesToStream(Const aStream : TStream); bla bla End; Type Generic TMyGeneric = Class(TFundamentalClass) Blabla End; Type TMySpecialization = Specialize TMyGeneric<String>; Did you tried that ? 2012/5/28 Kornel Kisielewicz <kornel.kisielew...@gmail.com>: > Hello all, > > I want to find a way to write a streaming mechanic for Generic data > structures. For simplicity let's assume that I want to write a class > or function to stream TFPGList (I do not use them, but my set of > generic classes is written in a similar manner). However, due to FPC's > restricted generics support I cannot find a way to reasonably do that. > > Ideally, I'd only like to write the streaming mechanism for each set > of types (normal, anisstring, dynamic array, objects, interfaced > objects) once, and use it for every set of items. However, there's no > reasonable way to detect the type and do an execution for it. Ideally > I'd be able to write a generic procedure : > > procedure StreamType( Stream : TStream; Data : T ); > > ... but we don't have generic procedures yet. Still, even if using > classes, the inability to do specializations makes it impossible to > write a generic streaming system. Is there a way to detect a type > easily of "any passed value"? It would be enough for me to have a > function > > procedure StreamType( Stream : TStream; var Data ); > > ... that could detect the type of data, as long as it would accept > simple types, ansistrings, classes and dynamic arrays. > > -- > regards, > Kornel Kisielewicz > http://chaosforge.org/ > _______________________________________________ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal