S
sunjunfeng3
Unregistered / Unconfirmed
GUEST, unregistred user!
我自定义了一个对象,把他的实例持久化到硬盘,然后再读回来的时候参数去选择了
type
TMyClass = class(TComponent) //自定义了一个对象
public
aaa:string;
end;
//持久化到硬盘文件
var
my:TMyClass;
fs: TFileStream;
begin
my := TMyClass.Create(self);
my.aaa := "aaaaaaaaaaaaaaaaaaaaaaaaa ";
fs := TFileStream.Create( "c:/test.txt ", fmCreate);
my := TMyClass.Create(self);
fs.WriteComponent(my );
fs.free();
end;
//再读回来
var
fs: TFileStream;
my1,my2:TMyClass;
begin
fs := TFileStream.Create( "c:/test.txt ", fmOpenRead);
ooo := fs.ReadComponent(my2);
my1 := TMyClass(ooo);
ShowMessage(my1.aaa); //这时候my1.aaa为空,为什么是空呢,上面我已经赋值了
end;
type
TMyClass = class(TComponent) //自定义了一个对象
public
aaa:string;
end;
//持久化到硬盘文件
var
my:TMyClass;
fs: TFileStream;
begin
my := TMyClass.Create(self);
my.aaa := "aaaaaaaaaaaaaaaaaaaaaaaaa ";
fs := TFileStream.Create( "c:/test.txt ", fmCreate);
my := TMyClass.Create(self);
fs.WriteComponent(my );
fs.free();
end;
//再读回来
var
fs: TFileStream;
my1,my2:TMyClass;
begin
fs := TFileStream.Create( "c:/test.txt ", fmOpenRead);
ooo := fs.ReadComponent(my2);
my1 := TMyClass(ooo);
ShowMessage(my1.aaa); //这时候my1.aaa为空,为什么是空呢,上面我已经赋值了
end;