1

I made a simple VCL form called TFormBase, and set some properties like for example WindowState = wsMaximized.

The form is also in a package that registers it, so my own properties are visible in the designer, that part works.

However, when I make a new form by

File / New / Other / Inheritable Items and then choose FormBase

the newly created form does not have the property WindowState = wsMaximized, also other properties are not taken over.

In the new form I do see this

type
  TFormBase1 = class(TFormBase)

so it does seem to inherit from TFormBase

Also when I put for example a button on FormBase, I expect this button to also appear on any form that derives from FormBase, that also does not happens.

Why is it that properties set on TFormBase are not taken over in forms that inherit from TFormBase ?

When I do Alt-F12 on the inherited form I see this

object FormBase1: TFormBase1

instead of this

inherited FormBase1: TFormBase1

And when I correct it, it jumps back to object FormBase1 : TFormBase1 The funny thing is, when I open the dfm file in notepad, it does shows inherited FormBase1 : TFormBase1 so the streaming from dfm to a form is causing it somehow.

Delphi 12 community, vcl project

EDIT

TFormBase is also registered in a Package like this

unit RegItems;

interface

uses
  Classes, DesignEditors, DesignIntf, frmBase;

  procedure Register;

implementation

procedure Register;
begin
  RegisterNoIcon([TFormBase]);
  RegisterCustomModule(TFormBase, TCustomModule);
end;

end.

If I uninstall this package, so FormBase is not registered (and thus my published properties are not visible anymore in the object inspector), then it works again !

But I would like to have both, and register so I can make custom properties, and be able to inherit from FormBase.

How to do that ?

Complete code of TFormBase for reference

unit frmBase;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TFormBase = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    FDataModuleName : string;
    FPrimaryKeyName : string;
  protected
    DataModule : TDataModule;
  public
  published
    property ggDataModuleName : string read FDataModuleName write FDataModuleName;
    property ggPrimaryKeyName : string read FPrimaryKeyName write FPrimaryKeyName;
  end;


implementation

{$R *.dfm}


procedure TFormBase.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := TCloseAction.caFree;
end;

procedure TFormBase.FormCreate(Sender: TObject);
var
  CRef : TPersistentClass;
begin
  if ggDataModuleName <> '' then
  begin
    CRef := GetClass(ggDataModuleName);
    if CRef <> nil then
    begin
       DataModule := TDataModule(TControlClass(CRef).Create(Self));
    end;
  end;
end;

end.
4
  • 1
    Why are you using event methods to set the initial state for your TFormBase? Doing so means that whenever a user will assign OnCreate or OnClose event to your base form or any of its derivatives none of your event methods will even fire since the OnCreate and OnClose event properties will now point to user made event methods. Instead you should override DoCreate and DoClose methods. Commented Jan 29 at 23:18
  • @SilverWarior OK I agree, but do you think this might also be the cause of my current problem? Commented Jan 30 at 6:38
  • At least give it a try. It is possible that wired events are not executed during design time. Commented Jan 30 at 8:58
  • @UweRaabe Sure, I will try it this evening at home, it's a hobby project I don't have delphi at work unfortunate. It stays weird though that without the registration of the form the visual inheritance works normal again, can't really see the connection but I will sure give it a try Commented Jan 30 at 9:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.