× Discussions for CodeTyphon Object Pascal Programming Language

Question How do I inherit a Form?

  • Roman
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 months 1 day ago - 4 months 1 day 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:
{ TCommonForm }
 TCommonForm = class(TForm)
  procedure FormCreate(Sender : TObject);
 private

 public

 end;
In the main module, I do this:
{ TForm1 }
 TForm1 = class(TCommonForm)
  procedure FormCreate(Sender : TObject);
 private

 public

 end;
and
procedure TForm1.FormCreate(Sender : TObject);
begin
  inherited;
end;
This 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:
{$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}

Is there such a predefined macro?
Last edit: 4 months 1 day ago by Roman.

Please Log in or Create an account to join the conversation.

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
More
4 months 1 day ago #15385 by Sternas Stefanos
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

PilotLogic Architect and Core Programmer

Please Log in or Create an account to join the conversation.

  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • I do love ObjectPascal and WinApi
More
4 weeks 2 days ago - 4 weeks 2 days 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.
(*
 *** 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: 4 weeks 2 days ago by 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰.

Please Log in or Create an account to join the conversation.

  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • I do love ObjectPascal and WinApi
More
4 weeks 2 days 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.