procedure TfrmMain.SaveToFile(FileName: string);
var
i : Integer;
lControl : TControl;
lWriter : TWriter;
aMemoryStream: TMemoryStream;
begin
aMemoryStream := TMemoryStream.Create;
aMemoryStream.Clear;
lWriter := TWriter.Create(aMemoryStream, 1024);
try
lWriter.Root := FWorkSpace;
for i := 0 to FObjects - 1 do
begin
lControl := TControl(FObject);
lWriter.WriteSignature;
lWriter.WriteComponent(lControl);
end;
lWriter.WriteListEnd;
finally
lWriter.Free;
end;
aMemoryStream.SaveToFile(FileName);
aMemoryStream.Free;
end;
上面是我的实际用的程序,略微改一下就可以了