Recent

Author Topic: Changing the superclass of IDE-generated forms  (Read 862 times)

pleumann

  • Jr. Member
  • **
  • Posts: 95
Changing the superclass of IDE-generated forms
« on: September 22, 2023, 09:56:43 am »
(Sorry for crossposting, but I did not get any answers in the Designer forum after two weeks and the question is somewhat important to our project.)

Hi,

I have a case where it would be convenient to extract common behavior of several forms into "something". I am thinking about a specialized TForm subclass TMyClass = class(TForm). Is it safe to change the superclass of IDE-generated forms to that class or will it cause trouble (with the IDE parsing the source code or other expectations)? I assume the designer uses a fixed class for the visual representation anyway, TForm or something else, so components added programmatically would not show up there, but that would be ok.

Best regards
Joerg

dsiders

  • Hero Member
  • *****
  • Posts: 1282
Re: Changing the superclass of IDE-generated forms
« Reply #1 on: September 22, 2023, 05:14:22 pm »
(Sorry for crossposting, but I did not get any answers in the Designer forum after two weeks and the question is somewhat important to our project.)

Hi,

I have a case where it would be convenient to extract common behavior of several forms into "something". I am thinking about a specialized TForm subclass TMyClass = class(TForm). Is it safe to change the superclass of IDE-generated forms to that class or will it cause trouble (with the IDE parsing the source code or other expectations)? I assume the designer uses a fixed class for the visual representation anyway, TForm or something else, so components added programmatically would not show up there, but that would be ok.

Best regards
Joerg

Custom form types can be added to the IDE and created at design-time (using File > New) and at run-time. Perhaps this article will offer some insight:
https://www.freepascal.org/~michael/articles/lazide2/lazide2.pdf
Preview the next Lazarus documentation release at: https://dsiders.gitlab.io/lazdocsnext

alpine

  • Hero Member
  • *****
  • Posts: 1303
Re: Changing the superclass of IDE-generated forms
« Reply #2 on: September 22, 2023, 07:59:48 pm »
@pleumann
The simplest way would be:
File -> New ... -> Inherited item -> Inherited project component -> Select your parent form there

"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

pleumann

  • Jr. Member
  • **
  • Posts: 95
Re: Changing the superclass of IDE-generated forms
« Reply #3 on: September 25, 2023, 04:24:44 pm »
Thanks, guys!

The second one is closer to what I aim to do. I don't want to install an extension to the IDE (because this can get a bit tedious if the project is edited on different machines and the extension is modified a lot). If I wanted to go that route I would create a new visual component and drop it onto all my forms.

Letting my forms inherit from a custom superclass means changes to the superclass get effective after a build of the project. I don't know yet how "far" this goes, but it seems the superclass can be in a different unit. Also, the object inspector shows me all compatible methods from the superclass when assigning an event handler. Perfect!

Best regards
Joerg

 

TinyPortal © 2005-2018