Workaround for saving and loading translations for eachform

All announcements, questions and issues related to the TsiLang Components Suite.
Post Reply
ursuletzu
Posts: 10
Joined: Mon Feb 02, 2004 9:43 am

Workaround for saving and loading translations for eachform

Post by ursuletzu »

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:

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;

isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

This is strange why something with loading doesn't work for you. Could you please create sample project which reproduces the wrong behavior and send it to us? Then we would try to investigate where the origin of problem is.
You may try to save/load to/from SIB files using SaveAllToBinaryFile/LoadAllFromBinaryFile methods which use the streaming as well. In this way you will be able to edit generated SIB files with SIL Editor.
ursuletzu
Posts: 10
Joined: Mon Feb 02, 2004 9:43 am

Post by ursuletzu »

From the Editor i can only save SIL files, but not SIB files...
Why?
ursuletzu
Posts: 10
Joined: Mon Feb 02, 2004 9:43 am

Post by ursuletzu »

OK, thanx for pointing out the SIB option.

Yes, when I save using SaveAllToBinaryfile the content is then CORRECTLY loaded with LoadAllFromBinaryFile.

Perhaps, being new to TsiLang, I didn't grasp the difference between SIL and SIB files...

Thanx again
Post Reply