[fpc-pascal] Streaming of Generics

Kornel Kisielewicz kornel.kisielewicz at gmail.com
Mon May 28 19:00:59 CEST 2012


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/



More information about the fpc-pascal mailing list