- Posts: 51
- Thank you received: 0
×
Discussions for CodeTyphon Object Pascal Programming Language
Question How do I inherit a Form?
- Roman
- Topic Author
- Offline
- Junior Member
-
Less
More
1 year 6 months ago - 1 year 6 months ago #15384
by Roman
How do I inherit a Form? was created by Roman
I need to implement almost the same interface in several projects. I want to create a base form class with immutable components, and then in the application make a form inheriting from this class, adding the necessary components (and inheriting the "base").
I create a module "my_form" in which I write:In the main module, I do this:andThis code compiles fine, the call to the inherited FormCreate method is done, the visual form editor works - everything is fine as intended. But this only works until IDE is closed or my project is closed. If I try to open this project with this description of my form, IDE hangs and then falls.
How can I properly inherit my form from my class, and not from the standard class TForm, in order to keep the form visually editable in the editor?
I am assuming that IDE and the compiler run at different times, so it would be possible to use the conditional compilation directives {$if}-{$else}, but this requires having a predefined macro that exists for "IDE"-time and does not exist for the compiler-time, for example:
Is there such a predefined macro?
I create a module "my_form" in which I write:
{ TCommonForm }
TCommonForm = class(TForm)
procedure FormCreate(Sender : TObject);
private
public
end;
{ TForm1 }
TForm1 = class(TCommonForm)
procedure FormCreate(Sender : TObject);
private
public
end;
procedure TForm1.FormCreate(Sender : TObject);
begin
inherited;
end;
How can I properly inherit my form from my class, and not from the standard class TForm, in order to keep the form visually editable in the editor?
{$if defined(IS_IDE_WORK)} // do not work!!! I figured it out later and corrected the message.
TForm1 = class(TForm)
{$else}
TForm1 = class(TCommonForm}
{$endif}
Last edit: 1 year 6 months ago by Roman.
Please Log in or Create an account to join the conversation.
- Sternas Stefanos
-
- Offline
- Moderator
-
- Ex Pilot, M.Sc, Ph.D
1 year 6 months ago #15385
by Sternas Stefanos
PilotLogic Architect and Core Programmer
Replied by Sternas Stefanos on topic How do I inherit a Form?
My suggestion, try to create your form in runtime manual.
Modules can handle only some of CT Components
Modules can handle only some of CT Components
PilotLogic Architect and Core Programmer
Please Log in or Create an account to join the conversation.
- 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
-
- Offline
- Junior Member
-
- I do love ObjectPascal and WinApi
Less
More
- Posts: 20
- Thank you received: 2
1 year 3 months ago - 1 year 3 months ago #15712
by 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
Replied by 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰 on topic How do I inherit a Form?
Untested but maybe possible with CT, Intercept the Unit and add whatever you like as base values/settings.
How-To:
create a unit called Interceptor.pas.
This way you can tweak TForm to whatever you want it to be.
Or add own methods to it, or or or....
How-To:
create a unit called Interceptor.pas.
(*
*** KodeZwergs Interceptor Example ***
copy "Interceptor.pas" into your Path where it's accessible from everywhere.
must be included as last "Uses" statement in "Interface" section to let it work automagically.
*)
unit Interceptor;
interface
uses
Forms;
type
{ interceptor class for TForm }
TForm = class(Forms.TForm)
protected
private
public
constructor Create(AOwner: TComponent); override;
public
end;
implementation
constructor TForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
// add more code here
end;
initialization
end.
This way you can tweak TForm to whatever you want it to be.
Or add own methods to it, or or or....
Last edit: 1 year 3 months ago by 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰.
Please Log in or Create an account to join the conversation.
- 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
-
- Offline
- Junior Member
-
- I do love ObjectPascal and WinApi
Less
More
- Posts: 20
- Thank you received: 2
1 year 3 months ago #15714
by 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
Replied by 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰 on topic How do I inherit a Form?
i completely forgot to mention that you can also make something different out of a TForm this way, the limitation of the possibilities is only in the imagination.
Please Log in or Create an account to join the conversation.