Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calling procs in separate forms

Posted on 1998-01-08
6
Medium Priority
?
161 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:jexd99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Accepted Solution

by:
ronit051397 earned 200 total points
ID: 1355852
You cannot write Form2.runthis because, then the Form2 is needed.
1.Create 2 forms.
2. Place a button in the main form.
3. copy the following:

PROJECT
-------

program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

FORM1
-----

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
uses unit2;
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowShow;
end;

end.

FORM2
-----

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm2 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;
procedure ShowShow;
var
  Form2: TForm2;

implementation

{$R *.DFM}
procedure ShowShow;
begin
  ShowMessage('This procedure is from form2');
end;
end.

0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1355853
It will work fine if you put the Runthis procedure in the public part of form2. Normally it should be ok then.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1355854
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Expert Comment

by:michael2010898
ID: 1355855
You can create form2 and then hide it and use it's procedures
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1355856
But s/he doesn't want to allocate extra memory for the form and it's components, just for a particular procedure.
0
 

Author Comment

by:jexd99
ID: 1355857
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question