Board index » delphi » Problems executing a procedure on a form from another form

Problems executing a procedure on a form from another form

I'm having a few problems geting one of my forms to run procedures from the
main application form.  What I'm trying to do is get my second form to add a
new menu to an existing one on the main form.  I have the main form in the
uses of the second.  Here's the line that I'm trying to use to add the menu:
  frmMain.mnuCustomCommands.Insert(0, frmNewCustom.newitem);
Every time it executes this line i get an Access Violation.  If anyone knows
how to get this to work I'd appreciate the help.

Thanks,
Jason

 

Re:Problems executing a procedure on a form from another form


Quote
> I'm having a few problems geting one of my forms to run procedures from the
> main application form.  What I'm trying to do is get my second form to add a
> new menu to an existing one on the main form.  I have the main form in the
> uses of the second.  Here's the line that I'm trying to use to add the menu:
>   frmMain.mnuCustomCommands.Insert(0, frmNewCustom.newitem);
> Every time it executes this line i get an Access Violation.  If anyone knows
> how to get this to work I'd appreciate the help.

Jason,

if you are trying to execute this line from the FormCreate method of
TFrmNewCustom it will blow up since the form reference has not yet been
assigned to frmNewCustom!

FormCreate executes from the tcustomform constructor, so it executes before
the

   frmNewCustom := TFrmNewCustom.Create( Application );

has returned from the Create call and assigned the generated form reference to
frmNewCustom.

It is generally not a good idea to refer to the form variable from inside a
method of the form and it is also not necessary, since all the components,
methods, properties of the form are directly accessible from any method of the
form.

So simply change the offending line to

  frmMain.mnuCustomCommands.Insert(0, newitem);
Peter Below (TeamB)  100113.1...@compuserve.com)

Other Threads