A: Use a stream to write to a disk file. The object must be a component and is written to the stream like this:
var Stream : TFileStream ;
begin
Stream := TFileStream.Create( 'AFile', fmCreate ) ;
try
Stream.WriteComponent( Button1 ) ;
Stream.WriteComponent( Grid1 ) ; etc.
finally
Stream.Free ;
end ;
end ;
To read it back, do this:
var Stream : TFileStream ;
Button2 : TButton ;
Grid2 : TStringGrid ;
begin
Stream := TFileStream.Create( 'AFile', fmOpenRead ) ;
try
Button2 := Stream.ReadComponent( nil ) as
TButton ;
Stream.WriteComponent( Grid1 ) ; etc.
finally
Stream.Free ;
end ;
end ;
At some point you need to register the classes you're going to write and read. For example, you could put the following in the forms OnCreate handler:
RegisterClass( TButton ) ;
RegisterClass( TStringGrid ) ;
If you don't register the classes you'll get a 'Class not found' error
when you try to read the object back.