Hi, I need a method to save a object (with structure and data) to a file, then recover the data to store it in object of the same type. (in the example I save object tim[1] and then load it from file to tim[2] they are teamme type).
I tried the procedure below, it works fine, but (it's hard to understand) when I add a new component in the main form it stop to work (i try to repeat the load procedure and now it get access violation). Anyone can help-me?
type
teamme = class(TPersistent)
public
name: string;
tjog: array[1..25] of jog;
end;
var
Form1: TForm1;
tim: array[1..100] of teamme;
procedure saveobj;
var
f: TFileStream;
begin
f:= TFileStream.Create('test.sav', fmCreate);
try
f.Writebuffer(tim[1],sizeof(tim[1]));
finally
f.Free;
end;
end;
procedure getobj;
var
o: TFileStream;
begin
o := TFileStream.Create('test.sav', fmOpenRead);
try
o.Readbuffer(tim[2],sizeof(tim[2])) ;
finally
o.Free;
end;
end;
I tried the procedure below, it works fine, but (it's hard to understand) when I add a new component in the main form it stop to work (i try to repeat the load procedure and now it get access violation). Anyone can help-me?
type
teamme = class(TPersistent)
public
name: string;
tjog: array[1..25] of jog;
end;
var
Form1: TForm1;
tim: array[1..100] of teamme;
procedure saveobj;
var
f: TFileStream;
begin
f:= TFileStream.Create('test.sav', fmCreate);
try
f.Writebuffer(tim[1],sizeof(tim[1]));
finally
f.Free;
end;
end;
procedure getobj;
var
o: TFileStream;
begin
o := TFileStream.Create('test.sav', fmOpenRead);
try
o.Readbuffer(tim[2],sizeof(tim[2])) ;
finally
o.Free;
end;
end;