SiComponents Home Page SiComponents Forums
Here you will be able to get help and share your experience
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Workaround for saving and loading translations for eachform

 
Post new topic   Reply to topic    SiComponents Forums Forum Index -> TsiLang Components Suite
View previous topic :: View next topic  
Author Message
ursuletzu



Joined: 02 Feb 2004
Posts: 10

PostPosted: Tue Feb 03, 2004 8:35 am    Post subject: Workaround for saving and loading translations for eachform Reply with quote

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:

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;

Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2097

PostPosted: Tue Feb 03, 2004 11:01 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
ursuletzu



Joined: 02 Feb 2004
Posts: 10

PostPosted: Wed Feb 04, 2004 1:52 pm    Post subject: Reply with quote

From the Editor i can only save SIL files, but not SIB files...
Why?
Back to top
View user's profile Send private message
ursuletzu



Joined: 02 Feb 2004
Posts: 10

PostPosted: Wed Feb 04, 2004 2:38 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SiComponents Forums Forum Index -> TsiLang Components Suite All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by p h p B B  © 2001, 2005 p h p B B  Group