> 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
You can use the "magic" function TypeInfo() to detect the type of a generic parameter inside a method of a generic class. It returns a PTypeInfo pointer so you can use PTypeInfo(TypeInfo(T))^ record to determine the data type (Kind) -and other attributes- of the generic type. For the lack of generic procedures, you can substitute a generic procedure with a generic class method: type generic TStreamer<T> = class public procedure StreamType( Stream : TStream; Data : T ); end; procedure TStreamer.StreamType( Stream : TStream; Data : T ); begin case PTypeInfo(TypeInfo(Data))^.Kind of tkString: ... tkInteger: .. end; end; HTH Constantine. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal