Read a component as a string

How to convert any component into a string.

function ComponentToString(Component: TComponent): string;

var

  BinStream:TMemoryStream;

  StrStream: TStringStream;

begin

  BinStream := TMemoryStream.Create;

  try

    StrStream := TStringStream.Create(Result);

    try

      BinStream.WriteComponent(Component);

      BinStream.Seek(0, soFromBeginning);

      ObjectBinaryToText(BinStream, StrStream);

      StrStream.Seek(0, soFromBeginning);

      Result:= StrStream.DataString;

    finally

      StrStream.Free;

    end;

  finally

    BinStream.Free



  end;

end;

 

Share this article!

Follow us!

Find more helpful articles: