Workaround for saving and loading translations for eachform
Posted: Tue Feb 03, 2004 8:35 am
I wanted to save each form's translation in a separate file.
So I tried to LoadAllFromFile but it seems not to work for me...
so I save the TsiLang component stream in a file for each form and load it again on demand:
So I tried to LoadAllFromFile but it seems not to work for me...
so I save the TsiLang component stream in a file for each form and load it again on demand:
Code: Select all
procedure TForm1.Load;
var
SS : TMemoryStream;
FF : TFileStream;
iSize : Cardinal;
sFileName : string;
begin
sFileName := IncludeTrailingBackslash(ExtractFilePath(Application.ExeName)) + 'test.cmp';
try
FF := TFileStream.Create(sFileName, fmOpenRead);
FF.Seek(0, soFromEnd );
iSize := FF.Position;
FF.Seek(0, soFromBeginning );
SS := TMemoryStream.Create;
SS.CopyFrom(FF, iSize);
SS.Seek(0, soFromBeginning);
siLang1.Owner.RemoveComponent(siLang1);
siLang1.Free;
siLang1 := SS.ReadComponent(nil) as TSiLang;
Self.InsertComponent( siLang1 );
finally
if Assigned(FF) then
FF.Free;
if Assigned(SS) then
SS.Free;
end;
end;
procedure TForm1.Save;
var
SS : TMemoryStream;
FF : TFileStream;
sFileName : string;
begin
sFileName := IncludeTrailingBackslash(ExtractFilePath(Application.ExeName)) + 'test.cmp';
try
SS := TMemoryStream.Create;
SS.WriteComponent( siLang1 );
SS.Seek(0, soFromBeginning);
FF := TFileStream.Create(sFileName, fmCreate);
FF.CopyFrom(SS,SS.Size);
finally
if Assigned(FF) then
FF.Free;
if Assigned(SS) then
SS.Free;
end;
end;