* * *

Author Topic: Derive a new form from a form I have created  (Read 895 times)

braunbär

  • Newbie
  • Posts: 3
Derive a new form from a form I have created
« on: September 15, 2018, 12:50:43 am »
Hi!

I would like to use a TmyForm that I have derived from TForm and to derive other forms from TMyForm.
While this is no problem with other components, it does not seem to work for forms.
Is there a solution?

RAW

  • Hero Member
  • *****
  • Posts: 678
Re: Derive a new form from a form I have created
« Reply #1 on: September 15, 2018, 01:06:07 am »
Can you show us a little example?
What exactly did you do?
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8.4 FPC 3.0.4 // 1.7 FPC 3.1.1

taazz

  • Hero Member
  • *****
  • Posts: 5342
Re: Derive a new form from a form I have created
« Reply #2 on: September 15, 2018, 01:16:48 am »
Hi!

I would like to use a TmyForm that I have derived from TForm and to derive other forms from TMyForm.
While this is no problem with other components, it does not seem to work for forms.
Is there a solution?
easily
Open you project with the form in question, make sure that the form is part of the project and not simple in the path. now go to file\New on the dialog that opens select the leaf Inherited project component from the tree on the lesft there you should see your TMyForm form and be able to selected to create a new form from it. I never used my self so how well this works I have no idea, but it should set up your code and lfm properly for inheritance. Oh there is a small bug though the designer fails to add the unit that TMyForm is in on the new form's uses clause and as a result the designer might complain that it can't find the TMyform class simple cancel loading or ignore the error and add the unit in the interface uses clause. close the new form and all its file and reopen it from the project manager it should work.

Disclaimer everything I typed above is from memory I never tested my memory if there are problem please post back with information of the exact error/excpetion lazarus and fpc version bitnes of the environment and everything else that might help us to identify the problem.
« Last Edit: September 15, 2018, 01:26:38 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

braunbär

  • Newbie
  • Posts: 3
Re: Derive a new form from a form I have created
« Reply #3 on: September 15, 2018, 02:01:55 pm »
@taazz
I did it quite exactly the way you describe, intuitively this is the way it should work. But it does not.

Here is an example that I have kept as simple as possible.
A project with just 2 units. In the object inspector, everything looks ok, form2 inherits button1 from form 1. Compiling also seems to work, but as soon as the program starts, it crashes. An empty form1 is painted on the screen (without buttons), then the program stops working and can only be stopped through the debugger halt, or, if the exe file is started without debugger, through  the task manager.

In some other constellations (with other unit dependencies), the derived form does not even show the properties of the inherited form in the OI.

wp

  • Hero Member
  • *****
  • Posts: 5035
Re: Derive a new form from a form I have created
« Reply #4 on: September 15, 2018, 04:54:26 pm »
The demo runs perfectly on my system: Laz trunk/fpc 3.0.4 (32 bit) on Win 10 (64 bit), but also Laz 1.6.4/fpc 3.0.2 and Laz 1.0/fpc 2.6.4.

What is your OS? Did you install any special components? Try with default settings (rename your profile folder to force Lazarus to create a new one with default settings).
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

RAW

  • Hero Member
  • *****
  • Posts: 678
Re: Derive a new form from a form I have created
« Reply #5 on: September 15, 2018, 07:29:21 pm »
Quote
The demo runs perfectly on my system ...
On my system too ...  :)

Maybe something like this is a good idea?
Code: Pascal  [Select]
  1. procedure TForm11.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  2. begin
  3.   CloseAction:= caFree;
  4.   Form11:= Nil;
  5. end;

Code: Pascal  [Select]
  1. begin
  2.   RequireDerivedFormResource:=True;
  3.   Application.Initialize;
  4.   Application.CreateForm(TForm1, Form1);
  5.   Application.Run;
  6. end.

Code: Pascal  [Select]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   If Not Assigned(Form11)
  4.   Then
  5.    Begin
  6.     Form11:= TForm11.Create(Nil);
  7.     Form11.Show;
  8.    End;
  9. end;
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8.4 FPC 3.0.4 // 1.7 FPC 3.1.1

braunbär

  • Newbie
  • Posts: 3
Re: Derive a new form from a form I have created
« Reply #6 on: September 19, 2018, 06:17:58 pm »
Thank you for your answers - My antivirus was responsible for the problems. When starting a program immediately after compiling it, there seems to be somtimes a deadlock situation, and the program crashes. These crashes have nothing to do with deriving a form, but the problem occured for the very first time, obviously due to an AV update, in such a constellation (and I have not done that yet with FPC before), and as the problem does not occur everytime, accidentally it looked like deriving a form was responsible.
« Last Edit: September 19, 2018, 06:19:35 pm by braunbär »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus