GuidoG
GuidoG

Reputation: 12014

Delphi 12 visual inheritance not working as I expect

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.

Upvotes: 1

Views: 98

Answers (0)

Related Questions