I still don't understand the problem. Let's assume you change your local variable myRec to be a parameter of both LoadFromStream(..) and SaveToStream(..). They both now look like this:
Delphi-Quellcode:
Procedure SaveToStream(const myRec:Tmyrecord);
var
SavingStream: TFileStream;
begin
SavingStream := TFileStream.Create('SAVE.test', fmCreate or fmOpenWrite or fmShareDenyWrite);
try
WriteStringToStream(SavingStream, myRec.Firstname);
WriteStringToStream(SavingStream, myRec.LastName);
WriteIntegerToStream(SavingStream, myRec.ID);
finally
SavingStream.Free;
end;
end;
procedure LoadFromStream(var myRec: TMyRecord);
var
LoadingStream: TFileStream;
begin
LoadingStream := TFileStream.Create('SAVE.test', fmOpenRead or fmShareDenyWrite);
try
myRec.Firstname:= ReadStringFromStream(LoadingStream);
myRec.LastName := ReadStringFromStream(LoadingStream);
myRec.ID := ReadIntegerFromStream(LoadingStream);
finally
LoadingStream.Free;
end;
end;
If you want to change the LastName field of some file from disk, then all you need to do is
Delphi-Quellcode:
var
myRec: Tmyrecord;
begin
LoadFromStream(myRec);
myRec.LastName := 'Wombat';
SaveToStream(myRec);
end;
The old file ("save.test") will get overwritten and the file will only contain the data stored in
myRec
.