Board index » delphi » D3: Creating a form via TFormClass, Constructors, and inherited forms

D3: Creating a form via TFormClass, Constructors, and inherited forms

Ok, this problem is kicking my butt.  It should be straight foreward, but me
and the other developers here are struggling over it.

In a nutshell:
What I'm trying to do create a universal menuing system that will handle the
menus for the 10 modules in our application.  I read the menu structure from
a table, and read the users security from a different table, taking the two
I build a menu for the user with the proper security features and options.
We do not use the autocreate for any form but the main menuing form.  Each
form that can be called from the menuing system has RegisterClass in the
Initialization section.

***********
Initialization
   RegisterClass(TfrmCaProcess);  // or whatever class the form is.
***********

The main menuing system builds the menu, then assigns a generic Menu OnClick
Handler, which takes the name of the menu item,  converts it to the correct
ClassName, does a GetClass to retrieve the TFormClass of the form to Create.

I have all of this working fine, but am struggling on actually creating the
forms themselves.

The problem is, all of our forms are inherited from a base form which has
security implemented as part of it's constructor.

************
type
  TfrmBaseForm = class(TForm)
.....
  public
     constructor Create(AOwner: TComponent; WhichSecurityPriv:
TAccessPrivs);
.....

constructor TfrmBaseForm.Create(AOwner: TComponent; WhichSecurityPriv:
TAccessPrivs);
begin
     // Assign the Access Priviledge Type (!!** Must happen first**!!)
     _AccessPriv := WhichSecurityPriv;
    // Create the inherited forms (ufrm Base Form...)
     inherited Create(AOwner);
end;

***********

If I do a create of the form via a normal create, it works fine.  But, doing
it this way prohibits me from using the generic menu handler for creating
and showing the forms....

frmCaProcess := TfrmCaProcess.Create(Application, WhichSecurityPriv);

If I do a create of the form via an Application.CreateForm, it creates the
form fine but does not execute the Create method of the base form, which
then does not pickup the security feature..

Application.CreateForm(MyFormClass, MyForm);

If I do a create of the form via my menuing system, the compiler does not
recognize the extra parameters in the create method, so I cannot run the
application.  If I change it to use the correct parameters it works fine
 MyForm := MyFormClass.Create(Application); )

In this example, MyFormClass is the TFormClass returned from a GetClass of
the correct form name.

***********
procedure TfrmMainMenu.MenuHandler(Sender: TObject);
var
    MyForm : TForm;
Begin
 .....
   MyForm := MyFormClass.Create(Application, WhichSecurityPriv);
 ...
end;
*********

If I try to cast the form to create as a type of the base form, it {*word*88}s
during the create method of the base form, it does not appear to recognize
the form as being the correct type.

*********
    MyForm := TfrmBaseForm(MyFormClass).Create(Application,
WhichSecurityPriv);
*********

So, I guess my question is how do I create a form if I know the form class
 as type TFormClass) so that it execcutes the create method of the form that
it is inherited from?

Any help, insight, thoughts, ideas, whatever would be greatly appreciated.
I'm stumped...

  Richard J. Werning
  TIP Technologies, Inc.
  r...@tiptech.com

 

Re:D3: Creating a form via TFormClass, Constructors, and inherited forms


Here is a working example of the problem for anyone that is interested in
helping...

begin 666 TestClass.zip
<encoded_portion_removed>
end

Re:D3: Creating a form via TFormClass, Constructors, and inherited forms


Quote
In article <34b26f3...@tornado.tcccom.net>, "R. Werning" <r...@tiptech.com> wrote:
>In a nutshell:
>What I'm trying to do create a universal menuing system that will handle the
>menus for the 10 modules in our application.  I read the menu structure from
>a table, and read the users security from a different table, taking the two
>I build a menu for the user with the proper security features and options.
>We do not use the autocreate for any form but the main menuing form.  Each
>form that can be called from the menuing system has RegisterClass in the
>Initialization section.

[SNIP]

Hi there.

I might be way off base here.. but bear with me.

I've brifly glanced through your code and the only thing that worries me is
that you might be incorrectly overriding your form's Create Method.

Follows a small code snippet I use to override form creation when I want to
pass extra parameters at form creation:

------------

type
  TFMStatsGrid = class(TForm)
  private
    { Private declarations }
    GridQuery : TQuery;
    procedure PopStatsGrid;
  public
    { Public declarations }
    constructor CreateForm(AOwner : TComponent; Qry1 : TQuery);
  end;

var
  FMStatsGrid: TFMStatsGrid;

implementation

uses
  dataprocs, data;
{$R *.DFM}
//////////
constructor TFMStatsGrid.CreateForm(AOwner : TComponent; Qry1 : TQuery);
begin
  GridQuery := Qry1;
  inherited Create(AOwner);
end;
-----------------

To create a form I just define it as FMStatsGrid : TFMStatsGrid

Then FMStatsGrid := TFMStasGrid.CreateForm(something, something).

Works like a dream.

Again, not sure if this is your problem but it is the only thing that bothered
me about your code.

Good luck.

Naz.

-------------------------------------------------------
Please remove xy from azizanxy to reply. Sorry
-------------------------------------------------------
The spam harvesters will have a ball with this puppy:
classo...@psbgm.qc.ca
root@localhost
admin@localhost
r...@mailloop.com
jo...@mailloop.com
jor...@earthlink.net
Chairman Reed Hundt: rhu...@fcc.gov
Commissioner James Quello: jque...@fcc.gov
Commissioner Susan Ness: sn...@fcc.gov
Commissioner Rachelle Chong: rch...@fcc.gov
abuse@localhost
postmaster@localhost admin@localhost
hostmas...@BEST.COM
ant...@PACIFIC-TECH.COM

Other Threads