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 

How does a Parent Form can get its own Strings?

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



Joined: 08 May 2008
Posts: 65

PostPosted: Thu Aug 07, 2008 10:09 pm    Post subject: How does a Parent Form can get its own Strings? Reply with quote

I have a hierarchy of inherited Forms for which only the lowest Child is instanciated.
When the Child uses a function of its parent, we get wrong strings.
The Parent calls to siLangRT1.GetTextOrDefault('IDS_0'...);, returns the Child's translation for IDS_0, not the Parent's one.

For example:
Code:
  TParentForm(TForm);
    function ParentString: String;
      begin
        Result := siLangRT1.GetTextOrDefault('IDS_0' (*Parent*));
      end;
      ...
  TChildForm(TParentForm); ...
    procedure FormShow;
      Caption := ParentString + ' > ' +
                 siLangRT1.GetTextOrDefault('IDS_0' (*Child*));
    ...

When Child's "FormShow" executes, its Caption gets the value
'Child > Child'
instead of
'Parent > Child'
This is because the Parent's function "ParentString" gets the Child's collection of strings instead of its own collection of strings!

Does the Parent's collection of strings available at Run Time, even if only the Child has been instanciated???

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


Joined: 21 Nov 2002
Posts: 2097

PostPosted: Fri Aug 08, 2008 4:10 am    Post subject: Reply with quote

No, Parent's strings are not available at run-time. When you instantiate child form only its resources (DFM) is available for Delphi as well as for TsiLang. This is why you get only child's strings. If you use inheritance and wish toi re-use strings from parent just be sure don't override their values in child and then use new IDs in child forms for new strings.
Back to top
View user's profile Send private message
Jean-Paul Brassard



Joined: 08 May 2008
Posts: 65

PostPosted: Fri Aug 08, 2008 2:10 pm    Post subject: How to access Parent's strings Reply with quote

isiticov wrote:
No, Parent's strings are not available at run-time. When you instantiate child form only its resources (DFM) is available for Delphi as well as for TsiLang. This is why you get only child's strings. If you use inheritance and wish to re-use strings from parent just be sure don't override their values in child and then use new IDs in child forms for new strings.

I did succeed with the following method. However, I have to explore to see if this could cause any problem. Like setting the Internal variable to nil on Form Destroy.

Standard Parent code which does not work, after adding TsiLang, when run from its Children:
Code:
var
  Parent_Form: TParent_Form;

implementation
  function ParentString: String;
    begin
      Result := siLangRT1.GetTextOrDefault('IDS_0' (*Parent*));
    end;

Potential solution to help fixing this problem:
Code:
type
  function Parent_Form: TParent_Form;

implementation
var
  InternalParent_Form: TParent_Form;

  function Parent_Form: TParent_Form;
  begin
    if NOT assigned(InternalParent_Form) then
      InternalParent_Form := TParent_Form.Create(Application);
    Result := InternalParent_Form;
  end;

  function ParentString: String;
    begin
      Result := Parent_Form.siLangRT1.GetTextOrDefault('IDS_0' (*Parent*));
    end;
Back to top
View user's profile Send private message
Jean-Paul Brassard



Joined: 08 May 2008
Posts: 65

PostPosted: Tue Aug 12, 2008 1:03 pm    Post subject: Re: How to access Parent's strings Reply with quote

Please forgot my previous "potential solution". Here is new info about that problem.
isiticov wrote:
No, Parent's strings are not available at run-time. When you instantiate child form only its resources (DFM) is available for Delphi as well as for TsiLang...

Update: The Parent's StringsCollection is not available at run time, but its strings ARE available through Child's StringsCollection. Here is how it works. When a Child is instantiated, Delphi propagates the FormCreate to all its Parents. While the parents are read by Delphi, TsiLang captures all their strings and adds them to the Child's StringsCollection.

Then, when the Child runs some Parent's code, the later gets its own strings back from its call to siLangRT1.GetTextOrDefault('IDS_27').

N.B. There are some restrictions.
1) The Parents must refer to the Child's siLangRT component, not its own one (which is nil). In other word, do NOT add the Form Name to the calls to siLangRT.
2) The Parent's strings IDs must differs from those of all its Children.
Back to top
View user's profile Send private message
Jean-Paul Brassard



Joined: 08 May 2008
Posts: 65

PostPosted: Tue Aug 12, 2008 3:53 pm    Post subject: Re: How to access Parent's strings Reply with quote

Jean-Paul Brassard wrote:
Update: The Parent's StringsCollection is not available at run time, but its strings ARE available through Child's StringsCollection...

Oups! Does not work when the Strings are read from an SIL or SIB file.
It is only OK whsn the strings are read from the DFM.
Back to top
View user's profile Send private message
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2097

PostPosted: Wed Aug 13, 2008 8:49 am    Post subject: Reply with quote

If you load translations from file it must contain all strings (parent's and child's) in child form section. Then they will be loaded into TsiLang when you load external file.
Back to top
View user's profile Send private message
Jean-Paul Brassard



Joined: 08 May 2008
Posts: 65

PostPosted: Wed Aug 13, 2008 4:14 pm    Post subject: How to get Parent's Strings when its Child is instanciated Reply with quote

isiticov wrote:
If you load translations from file it must contain all strings (parent's and child's) in child form section. Then they will be loaded into TsiLang when you load external file.

I coded the new utility "AddParentStrFromSIB" which reads the Parent's strings from the SIB file, into its Child's StringCollection. This way, when the Child uses one of its Parent's property, the Parent strings are there and translated.

I let TsiLang publish my solution, if its is OK with their copywrights.
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