0

Using Delphi XE3, I'm trying to add a published property to a form in such a way that when I open the form in the IDE, the property appears in the object inspector.

I've tried following the steps in this question and I think I've done them correctly, but the property does not appear.

What I've done so far:

  • Create a new project with a new form, with the published property:
unit TestRegU;

interface

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

type
  TfrmTestReg = class(TForm)
  private
    { Private declarations }
    FSampleProperty: Integer;
  public
    { Public declarations }
  published
    property SampleProperty: Integer read FSampleProperty write FSampleProperty;
  end;

var
  frmTestReg: TfrmTestReg;

implementation

{$R *.dfm}

end.
  • Create a new package. Inside the package, added a unit which registers the form using RegisterCustomModule:
unit RegItems;

interface

uses
  Classes, DesignEditors, DesignIntf, TestRegU;

  procedure Register;

implementation

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

end.
  • I've also added the form to the package:
package TestRegPkg;

{$R *.res}
{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users}
{$ALIGN 8}
{$ASSERTIONS ON}
{$BOOLEVAL OFF}
{$DEBUGINFO ON}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS ON}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION OFF}
{$OVERFLOWCHECKS OFF}
{$RANGECHECKS OFF}
{$REFERENCEINFO ON}
{$SAFEDIVIDE OFF}
{$STACKFRAMES ON}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST OFF}
{$MINENUMSIZE 1}
{$IMAGEBASE $400000}
{$DEFINE DEBUG}
{$ENDIF IMPLICITBUILDING}
{$IMPLICITBUILD ON}
{$DESIGNONLY ON}

requires
  rtl,
  vcl,
  designide;

contains
  TestRegU in '..\TestRegPrj\TestRegU.pas' {frmTestReg},
  RegItems in 'RegItems.pas';

end.

  • I successfully compile and install the package.

  • When I re-open the TfrmTestReg form, the property is not visible in the object inspector:

missing property

Any insight on what I'm missing would really help. Sample code here.

Kieran
  • 718
  • 1
  • 16
  • 33
  • 2
    IIRC in your project use a *descendant* of your `TfrmTestReg`. – Ondrej Kelle Sep 11 '19 at 16:14
  • 2
    You have to create a form that descends from `TfrmTestReg`. TForm does not contain such a property, and it's currently the base for the form in the Object Inspector. The OI creates the form based on TForm and then streams properties in order to set values, and TForm does not contain a `SampleProperty` which can be set. `TfrmTestReg` does, and so it's descendants will know about it and so will the Object Inspector. – Ken White Sep 11 '19 at 17:53
  • Thanks @KenWhite, I've tested that and it works. If you make that an answer, I'll accept. – Kieran Sep 12 '19 at 08:55

0 Answers0