Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-11

setting a custom driver in TReader

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Roland Schaefer

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);
  ;
  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