Welcome, Guest
Username: Password: Remember me
Discussions for CodeTyphon Object Pascal Programming Language
  • Page:
  • 1

TOPIC:

How do I inherit a Form? 3 years 3 months ago #15384

  • Roman
  • Roman's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 88
  • Thank you received: 0
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?

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

Last edit: by Roman.

How do I inherit a Form? 3 years 3 months ago #15385

  • Sternas Stefanos
  • Sternas Stefanos's Avatar
  • Offline
  • Moderator
  • Moderator
  • Ex Pilot, M.Sc, Ph.D
  • Posts: 4508
  • Thank you received: 1100
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.

How do I inherit a Form? 3 years 3 weeks ago #15712

  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • I do love ObjectPascal and WinApi
  • Posts: 20
  • Thank you received: 2
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....
 

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

Last edit: by 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰.

How do I inherit a Form? 3 years 3 weeks ago #15714

  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰
  • 𝓚𝓸𝓭𝓮𝓩𝔀𝓮𝓻𝓰's Avatar
  • Offline
  • Junior Member
  • Junior Member
  • I do love ObjectPascal and WinApi
  • Posts: 20
  • Thank you received: 2
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.

  • Page:
  • 1