Link to home
Start Free TrialLog in
Avatar of jexd99
jexd99

asked on

Calling procs in separate forms

Ok, I know Delphi is susposed to be able to do this (so I think), but I cannot get this to work. Form1/Unit1 is the primary form, and I want to call a procedure in Form2/unit2, without having Form2 showing. Lets say the procedure in form2 is called "runthis";
--------
Form1
uses unit2...
.
begin
  Form2.runthis;
.
.
.
-----------
Form2
.
.
.
procedure runthis;
begin
  messagedlg....
end;
.
.
This is a basic example, and I thought this would be a simple solution, but I can't seem to to get past the compiler no matter what I try. I have tried putting the procedue header in the implementation section on form2, but that doesn't seem to get past the compiler either.  Can I do this in Delphi?  
           Thanks
ASKER CERTIFIED SOLUTION
Avatar of ronit051397
ronit051397

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ZifNab
ZifNab

It will work fine if you put the Runthis procedure in the public part of form2. Normally it should be ok then.
In order to use the public procedures you need to load the
Form2, but he/she want's to use the procedure without loading the form.
You can create form2 and then hide it and use it's procedures
But s/he doesn't want to allocate extra memory for the form and it's components, just for a particular procedure.
Avatar of jexd99

ASKER

Hooray!  It worked. :-)  I was having such a tough time with something so easy.  It looks like my major problem was placing the procedure header in the wrong place.  Anyway, I'm just glad it worked, and it even works without creating the 2nd form! Cool. :)
Thanks to all of you for your comments.