TTypedFiler is similar to TFiler as in it can be assigned to a Stream for reading and writing. However, TypedFiler has support for more complexed types, correctly writes multi-dimensional variant arrays and is interfaced based.

Typed Stream can read and write the following types:

  • Boolean, Byte, Cardinal, Currency, Color, DateTime, Exception, Float, Font, GUID, Int64, Integer, IP Address, ShortInt, Single, SmallInt, Streams, String, Variant, WideString, Word

In addition to these basic types:

  • Encrypted Streams – using TurboPowerLockBox
  • Compressed Streams – using TurboPowerAbbrevia
  • Pictures – Any TPicture compatible format.
  • Version – A helper type to allow you to add versioning to the streams.

The Class is interfaced based and descends from TInterfacedObject so you don’t even need to free the filer.

Example Code To Write to a Stream

procedure WriteToStream(AStream: TStream);
var
Filer : TTypedFiler;
begin
Filer := TTypedFiler.create(Astream);
Filer.WriteCardinal($FFFFFFFF);
Filer.WriteWideString(‘My String’);
end;

Example Code To Read from a Stream

ProcedureReadFromStream(AStream : TStream);
var
Filer : TTypedFiler;
begin
Filer := TTypedFiler.create(Astream);
Filer.GotoStart;
ACardinal := Filer.ReadCardinal;
if Filer.ReadNextType = TS_Widestring then
AStr := Filer.ReadWideString();
end;

Typed Filer can be here: TypedFiler

Leave a Reply