[fpc-pascal] setting a custom driver in TReader

Roland Schaefer roland.schaefer at fu-berlin.de
Thu Nov 5 22:58:24 CET 2009


Hi,

I'm wondering how to set a custom driver object for TReader instances.
Both in TReader and TWriter the Driver property is read-only, but in
TWriter I can at least use the alternative constructor which takes a
TAbstractObjectWriter. TReader only has the constructor which takes a
TStream and a buffer size Integer. Why is that?

Actually, this slightly ugly snippet from LResources/CreateLRSReader
shows that I'm not the only one trying to do this (where Result is a
TReader instance):

  // hack to set a write protected variable.
  // DestroyDriver:=true; TReader will free it
  Driver:=LRSObjectReaderClass.Create(s,4096);
  p:=@Result.Driver;
  Result.Driver.Free;
  TAbstractObjectReader(p^):=Driver;


Any hints why this is implemented as it is, and whether there are
cleaner ways of using custom drivers would be highly appreciated.

Cheers
Roland



More information about the fpc-pascal mailing list