Recent

Author Topic: Question about OOP (a custom constructor)  (Read 15179 times)

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Question about OOP (a custom constructor)
« Reply #15 on: February 24, 2011, 04:49:14 pm »
I can't find the class to which the "AComponent is" will respond in the case of TMainMenu and TPopupMenu. Does anyone have the answer? :D

TMenuItem, TMAinMenu and TPopUpMenu (among others) are declared in the unit Menus.


idealis

  • New Member
  • *
  • Posts: 34
Re: Question about OOP (a custom constructor)
« Reply #16 on: February 25, 2011, 12:50:27 pm »
Finally! Garlar27, I know where the classes are defined, but the problem was that I couldn't understand where to put that code, I was getting SIGSEGV on menu items everywhere. :-\

I finally got it to work like this:

Code: Pascal  [Select][+][-]
  1. constructor TTokenForm.Create(AOwner: TComponent; DatosToken: TToken);
  2. begin
  3.   Token := DatosToken;
  4.   inherited Create(AOwner);
  5.   WriteCaption(Self);
  6. end;
Code: Pascal  [Select][+][-]
  1. procedure TTokenForm.WriteCaption(AComponent: TComponent);
  2. var
  3.   i: Integer;
  4. begin
  5.   if (AComponent is TLabel) or (AComponent is TStaticText) or (AComponent is TCustomButton) or (AComponent is TForm) then
  6.     begin
  7.       if (AComponent.Tag <> 0) then TLabel(AComponent).Caption := LeerTextoGUI(AComponent.Tag);
  8.     end
  9.   else if (AComponent is TMenuItem) then
  10.     begin
  11.       if (AComponent.Tag <> 0) then TMenuItem(AComponent).Caption := LeerTextoGUI(AComponent.Tag);
  12.     end;
  13.   for i := 0 to AComponent.ComponentCount-1 do WriteCaption(AComponent.Components[ i ]);
  14. end;
So the form is created as easily as
Code: Pascal  [Select][+][-]
  1. NewForm := TfrmMain.Create(nil,Token);
As always, thanks for the big help! Cheers! :D

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Question about OOP (a custom constructor)
« Reply #17 on: February 25, 2011, 08:07:13 pm »
Quote
Finally! Garlar27, I know where the classes are defined, but the problem was that I couldn't understand where to put that code, I was getting SIGSEGV on menu items everywhere.

Sorry, some times I missunderstand the questions  :-[ ... you know, English is not my native language...


   Constructors and Create events procedures they're allways "tricky" when you want to do something with class' objects which are not created by you.
   This is something that I can tell because I had those problems before and hopefully I won't do it again  :-[

 

TinyPortal © 2005-2018