Strings Delphi

Title: How to get a string representation of an object
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;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage(ComponentToString(Button1));
end;