怎样恢复被删除的对象?难!!!!(50分)

  • 主题发起人 主题发起人 笑他
  • 开始时间 开始时间

笑他

Unregistered / Unconfirmed
GUEST, unregistred user!
如果你删除了一个对象,怎样恢复?就像设计undelete的效果?
观察delphi设计时所作的,实际上保存了一些文本信息如:
object Edit1: TEdit
Left = 16
Top = 40
Width = 121
Height = 21
TabOrder = 10
Text = 'Edit1'
end
然后根据这些信息产生控件。
通过ComponentToString(edit1)可以获得以上信息;
但通过stringtoComponent(Edit2.text)却报错;
怎么回事?
以上两个函数在帮助中可见。
 
用内存流WriteComponent应该可以
 
To shenloqi
用的就是writeComponent,可是出错!
现将我用的函数贴于下:
function ComponentToString(Component: TComponent): string;

var
BinStream:TMemoryStream;
StrStream: TStringStream;
s: string;
begin
BinStream := TMemoryStream.Create;
try
StrStream := TStringStream.Create(s);
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;

function StringToComponent(Value: string): TComponent;
var
StrStream:TStringStream;
BinStream: TMemoryStream;
begin
StrStream := TStringStream.Create(Value);
try
BinStream := TMemoryStream.Create;
try
ObjectTextToBinary(StrStream, BinStream);
BinStream.Seek(0, soFromBeginning);
Result := BinStream.ReadComponent(nil);

finally
BinStream.Free;
end;
finally
StrStream.Free;
end;
end;
 
把对象的特性存到一个内存流里,然后再读出来
 
多人接受答案了。
 
后退
顶部