[Lazarus] pascal component stream

Max Vlasov max.vlasov at gmail.com
Mon Jan 17 11:18:06 CET 2011


On Mon, Jan 17, 2011 at 1:45 AM, Mattias Gaertner <nc-gaertnma at netcologne.de
> wrote:

> Hi,
>
> Point 4 is the real problem. How to store TStrings.Data or TBitmap.Data?
>
>
When the topic appears some time ago, I experimented creating procedure
converting dfm text form into delphi code. Point 4 was a real challenge.

For TStrings it was just assuming if token is '(' then it's TStrings
(possible not always true, but there are so many TStrings inside *CL and
user's codebase this is almost safe to assume)

For binary data (token '{') was a more complex thing.
As a self-explaining example, the following code from TImage dfm. I made it
in Delphi, but surprisingly (or not depending on the person) Lazarus
accepted the converted approach without any problem :) As long as I
remember, in Delphi data from TTreeview was always successfully converted.

****************** begin of fragment *************************

object Image1: TImage
  Left = 184
  Top = 16
  Width = 49
  Height = 33
  Picture.Data = {
    07544269746D617076010000424D760100000000000036000000280000000A00
    .....}
end

was converted to

...
  TReaderHack = class(TReader);
....

  Image1.Left := 184;
  Image1.Top := 16;
  Image1.Width := 49;
  Image1.Height := 33;
  DataString:=

#7'TBitm'+'apv'#1#0#0'BM'+'v'#1#0#0#0#0#0#0'6'#0#0#0'('#0#0#0+#10#0+#0#0+...;
  Insert(#4'Data'+Chr(Ord(vaBinary)) + #130#1#0#0, DataString, 1);
  Stream:=TStringStream.Create(DataString);
  try
    Reader:=TReaderHack.Create(Stream, 1024);
    try
      Reader.ReadProperty(Image1.Picture);
    finally
    Reader.Free;
    end;
  finally
    Stream.Free;
  end;


****************** end of fragment *************************

btw, since Lazarus is oss, the hack for TReader here that is needed only to
call protected method, can be solved other way.

Max Vlasov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110117/abb8e18c/attachment-0003.html>


More information about the Lazarus mailing list