Board index » delphi » CREATE OR CREATE NEW

CREATE OR CREATE NEW

Hi dudes!
This has been a long-term niggle with stuff I have written in Delphi 1.0
for some time, I have tried to call Create or CreateNew in the constructor
in any way I
thought and still get exceptions, I have included a snippet of the sort of
thing i am doing below
which i suppose is all about inheritance, but I can't get it to work ?

Up 'til now the way that i have done it is to create the new object as just
a class and add  a form that I want to inherit in the the class declartion,
this works fine
but I figured there must be a better way, right?
So, if I remove the added form  declaration ( marked *****) and use
CreateNew it bombs! but Create is fine if used as below.
I would be EXTREMELY grateful for your coments/sample as I have about 10
forms done in this way!

So, for example the base form designed in the IDE ( which has a RES dfm )
is this....

TOptForm = class(TForm)
   OptMsg:TLabel;  
   OptShadow:TShape;
   OptPanel:TPanel;
   OptOK:TBitBtn;   OptCancel:TBitBtn;    OptHelp:TBitBtn;
   procedure OptOKClick(Sender: TObject);
   procedure OptCancelClick(Sender: TObject);
   procedure OptHelpClick(Sender: TObject);
   procedure OptButtonMove(Sender:TObject; Shift:TShiftState; X,Y:Integer);
   procedure OptButtonEnter(Sender: TObject);
   procedure OptPanelResize(Sender: TObject);
 private
   FLastButton: TBitBtn;
   FBtnBMP: array[0..2] of String;
   function  GetOptMsg:String;
   procedure SetOptMsg(Msg:String);
   procedure OneEditBox(TheForm:TForm; ThePanel:TPanel; Sender:TEdit);
 public
      FHelp: String;
    FMaxVals: array[0..MaxOptItems] of Real;
    FMaxChar: array[0..MaxOptItems] of Integer;
    FEditLabels,FEditValues: array[0..MaxOptItems] of string;
    constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
      function GetOption(NItems,OldTag:Integer):Integer;
      function GetEdit(NItems,AutoSel:Integer):Integer;
     procedure MakeBig(Sender:TForm);
      property OptHint:string read GetOptMsg write SetOptMsg;
 end;

Then, when I want to reuse add or change this I do something like this...
From the TObject base class.......

TAPMeter = class
public
   OneMeter:TGauge;
  {********** if  I remove this and do TAPMeter = class(TOptForm) it don't
work  ...  }
  MeterForm:TOptForm;  
  { **********  ^^^ if I leave it in its OK }
 constructor Create(AOwner:TComponent);
   destructor Destroy;
end;

j...@autopro.u-net.com
--
Jeff @ AutoPro Software UK

--
Jeff @ AutoPro Software UK

 

Re:CREATE OR CREATE NEW


Quote
Jeff <j...@autopro.u-net.com> wrote:
> This has been a long-term niggle with stuff I have written in Delphi 1.0
> for some time, I have tried to call Create or CreateNew in the constructor
> in any way I
> thought and still get exceptions, I have included a snippet of the sort of
> thing i am doing below
> which i suppose is all about inheritance, but I can't get it to work ?

That's rather easy: if you use Create you need to have a fitting DFM file,
but if you use CreateNew no DFM reading is done. So you can create a
inherited form of your standard one (which has a DFM entry) by overriding
the CreateNew and in this call the inherited Create to load the base form
with it's DFM. If you call inherited CreateNew you will have a form without
any DFM reading, and if you override the Create then a DFM for the derived
form name is searched (and of course not found).

Bye,
   Andy

--
----------------------------------------------------------------------------
Andreas H"orstemeier                       | "We are not interested in
email: a...@scp.de                           | little green men, but in little
       a...@hoerstemeier.de                | green women."
www:   http://www.westend.de/~hoerstemeier | (Edwin "Buzz" Aldrin)
fido:  2:2452/108                          |
----------------------------------------------------------------------------  

Other Threads