S
sunjunfeng4
Unregistered / Unconfirmed
GUEST, unregistred user!
在序列化的时候,TFileStream可以但TMemoryStream却报异常的情况
先用TFileStream对象,是没问的题
procedure TForm1.Button1Click(Sender: TObject);
var
my,my1,my2:TMyclass;
m:TFileStream;
o:tcomponent;
begin
my := TMyclass.Create(nil);
my1 := TMyclass.Create(nil);
my2 := TMyclass.Create(nil);
m:= TFileStream.Create('c:/temp.txt',fmcreate);
m.WriteComponent(my);
m.Free;
m:= TFileStream.Create('c:/temp.txt',fmOpenRead);
o:= TComponent.Create(nil);
o := m.ReadComponent(my1) ;
my2:= TMyClass(o);
m.Free;
end;
换成TMemoryStream却报异常
procedure TForm1.Button1Click(Sender: TObject);
var
my,my1,my2:TMyclass;
m:TMemoryStream;
o:tcomponent;
begin
my := TMyclass.Create(nil);
my1 := TMyclass.Create(nil);
my2 := TMyclass.Create(nil);
m:= TMemoryStream.Create;
m.WriteComponent(my);
m.Free;
m:= TMemoryStream.Create;
o:= TComponent.Create(nil);
o := m.ReadComponent(my1) ; //这里报异常
my2:= TMyClass(o);
m.Free;
end;
先用TFileStream对象,是没问的题
procedure TForm1.Button1Click(Sender: TObject);
var
my,my1,my2:TMyclass;
m:TFileStream;
o:tcomponent;
begin
my := TMyclass.Create(nil);
my1 := TMyclass.Create(nil);
my2 := TMyclass.Create(nil);
m:= TFileStream.Create('c:/temp.txt',fmcreate);
m.WriteComponent(my);
m.Free;
m:= TFileStream.Create('c:/temp.txt',fmOpenRead);
o:= TComponent.Create(nil);
o := m.ReadComponent(my1) ;
my2:= TMyClass(o);
m.Free;
end;
换成TMemoryStream却报异常
procedure TForm1.Button1Click(Sender: TObject);
var
my,my1,my2:TMyclass;
m:TMemoryStream;
o:tcomponent;
begin
my := TMyclass.Create(nil);
my1 := TMyclass.Create(nil);
my2 := TMyclass.Create(nil);
m:= TMemoryStream.Create;
m.WriteComponent(my);
m.Free;
m:= TMemoryStream.Create;
o:= TComponent.Create(nil);
o := m.ReadComponent(my1) ; //这里报异常
my2:= TMyClass(o);
m.Free;
end;