What's wrong with my code / form inheritance lazarus / 31-LCL ---------------------------------------------------------------------- hy · 2014-11-11 14:06 Hi I am having a problem with formCreate. I have a Form named QCustomForm which is a descendant of TForm and implements some basic things that I want to have in all my forms. Furthermore I have a descendant of  QCustomForm (QForm)  which implements more stuff that I need (less often). For demonstration purposes I have removed almost anything from these Forms. Problem is, that the overridden constructor Create is not executed. What am I doing wrong? I used to have these forms in some Delphi applications and I am sure it worked. ATM I do not have any windows machine ' so I can not countercheck in Delphi. Attached you will find the source that doesn't work. ---------------------------------------------------------------------- Never · 2014-11-11 15:24 i'm not able to review your code but you have to  use createnew insted of create if your form is resourceless ---------------------------------------------------------------------- Leledumbo · 2014-11-11 15:30 http://wiki.freepascal.org/Lazarus_1.0_release_notes#TCustomForm.Creat e_raises_an_exception_if_resource_is_not_found ---------------------------------------------------------------------- hy · 2014-11-11 16:31 No that is not the problem. I just omitted too much in order to reduce the problem to the relevant stuff. I've attached another archive, that also contains the lfms... the problem is that constructor Create is not executed. ---------------------------------------------------------------------- Bart · 2014-11-11 17:56 Code: [Select]constructor TForm1.create(AOWNER : TComponent); begin    inherited create(AOWNER); end; This calls TForm.Create, because you have not overridden the Create for either QCustomForm or QForm. Another thing that strikes me as odd: TQCustomForm: Code: [Select] constructor   CreateNew(AOwner : TComponent); virtual; //<- did you mean override? Bart ---------------------------------------------------------------------- howardpc · 2014-11-11 18:59 I cut down your scheme to its barest essentials, and put in new constructors which are declared with override, and call the correct inherited methods. I also placed the inherited calls before memory allocation for any internal class variables such as _FHooks (a TList). See attached project which compiles and (briefly tested) runs OK for me. ---------------------------------------------------------------------- hy · 2014-11-11 19:11 Thanks indeed it was just override instead of virtual. IIRC I had some trouble with delphi using the override directive in constructors... That's why I got used to declaring it as virtual. The other stuff (allocating memory b4 calling inherited) is a result of downsizing a 100.000-lines project to the actual problem and playing around with it. Thanks for your help ---------------------------------------------------------------------- taazz · 2014-11-11 20:04 Quote from: hy on November 11, 2014, 08:11:10 pmThanks indeed it was just override instead of virtual. IIRC I had some trouble with delphi using the override directive in constructors... That's why I got used to declaring it as virtual. Oh this is so wrong, by declaring it as virtual instead of overriding it you effectively breaking the chain of execution forcing the existing libraries to ignore your code, if you are used to it I would love to see that library. ---------------------------------------------------------------------- hy · 2014-11-11 20:50 It worked. I do not have any Windows Computer and can not countercheck. But in 2005 (when I was working with Delphi for the last time) I remember clearly that I had problems. That's why I used virtual. and the code was executed. I have classes with a whole a lot of code in the constructor. It would never have worked without the execution of these constructors. ---------------------------------------------------------------------- taazz · 2014-11-11 22:04 Quote from: hy on November 11, 2014, 09:50:48 pmIt worked. I do not have any Windows Computer and can not countercheck. But in 2005 (when I was working with Delphi for the last time) I remember clearly that I had problems. That's why I used virtual. and the code was executed. I have classes with a whole a lot of code in the constructor. It would never have worked without the execution of these constructors. Consider your self lucky. ---------------------------------------------------------------------- hy · 2014-11-14 13:13 Well, now I remember what the problem was. If I need more parameters in Constructor I can not override the inherited constructor. It's the same with lazarus. In these cases I need virtual. e.g. Code: [Select]constructor Create(AOwner: TComponent; sSomeThing: string); virtual; ---------------------------------------------------------------------- taazz · 2014-11-15 04:05 Quote from: hy on November 14, 2014, 02:13:47 pmWell, now I remember what the problem was. If I need more parameters in Constructor I can not override the inherited constructor. It's the same with lazarus. In these cases I need virtual. e.g. Code: [Select]constructor Create(AOwner: TComponent; sSomeThing: string); virtual;� In this case you need the reintroduce keyword not virtual ---------------------------------------------------------------------- hy · 2014-11-15 07:43 taaz: Ok thanks. ---------------------------------------------------------------------- howardpc · 2014-11-15 09:34 A minor point: reintroduced methods are no longer virtual. So if hy wants a truly virtual constructor with parameters differing from any (otherwise inheritable) constructor, he would need to give his new virtual constructor a new name (and of course declare it as virtual).