[fpc-pascal] Any recommendations for a good in-memory storage type

Marco van de Voort marcov at stack.nl
Wed Sep 22 12:52:51 CEST 2010

In our previous episode, Graeme Geldenhuys said:
> While implementing drag-n-drop support in fpGUI, I created a
> TfpgMimeData class. This class will hold various data items, and a
> mime-type describing each of the data items. Obviously the
> TfpgMimeData class should be able to handle any data type. So my
> question is, what is a good universal type to store all kinds of data
> (strings, images (binary data), sound etc)?
> The possible ideas I can think of is the following:
>   TByteArray
>   Variants
>   TMemoryStream

Different choices. The question is if you want some typing (if only runtime)
and easy conversions, or e.g. have the data in a directly writable format.

It depends on what you do most, operating on the data, or not.

e.g. You can easily assign a string to a variant, but for the rest you need to
more or less stream it. Same for e.g. classes.

At the same time, you can very quickly dump bytearrays to disc (and
tmemorystream is only a thin wrapper around one).

So what do you do more?

I would first try a variant.
(the example code doesn't perform any action on the data of the mimetype,
so it doesn't really add anything IMHO)

More information about the fpc-pascal mailing list