Solved

Delphi Programming question

Posted on 1997-09-23
4
176 Views
Last Modified: 2010-04-04
This one is probably simpler than I am making it, but I am adding a new form to an existing project, but I want the new form to call procedures in the old form.  If the new form is called "formnew" and the existing form is called formexist, Is there a way I can access formexists procedures from the new form, formnew?  I don't want to add duplicate code in the "formnew".  (I know I can have a separate pascal unit and just include it in both forms uses clause, but I don't want to do that). What is the easiest way of doing this, or is there a way I can do this? (I may be totally missing the boat on this one, so even pointing me in the right direction would be helpful).
0
Comment
Question by:jexd99
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
jturpin earned 0 total points
ID: 1346062
You pretty well have to put the unit in your uses clause.

However, the best way is to put the name of the FormExist
unit in the implementation section of the FormNew unit.

e.g.

.
.
Implementation

      uses
         FormExistUnit;


If you really don't want to do this, for some reason,
try and pull the routines you want out of FormExist
and put them in a seperate unit. Then put this unit
in the uses statement under Implementation in
both FormExist, and FormNew.

John.
0
 

Author Comment

by:jexd99
ID: 1346063
I probably didn't explain this quite right, but the first part that you mention above is exactly what I want to do, and the second part (putting the same unit in each uses) is what I want to avoid.
Everytime I try placing the formexist unit in the formnew uses clause, and then I have one line in formnew which calls a proc in formexist, the compiler doesn't recognize the proc name?

i.e.
formexist {this is the main form}
  .
  .
procedure test;
----------------
formnew   { new form added to formexist }
uses
   formexistunit

Now if I call "test" here, the compiler doesn't recognize this.
Can this be done this way?
-----------------
Thanks
(If necessary, I may have to just pull the code out as a separate unit, then add the unit to each form as you mentioned in step 2.)
0
 
LVL 1

Expert Comment

by:jturpin
ID: 1346064
Is your procedure defined as:
#1)   procedure Test;
or
#2)   procedure TFormExist.Test;

If it is defined as #1 then you need to declare Test
in the interface section of FormExist like:
   Interface
   .
   .
      Procedure Test;
   .
   Implementation


If it defined as #2 then you need to ensure that the routine
is not in the private section, and not in the protected
section of FormExist.
   FormExist = class(TForm);
     .
     {Here maybe}
     .
   private
     procedure Test; {NOT HERE}
   protected
     {NOT HERE}
   public
     {Here maybe}
   end;

ok.

John.
0
 

Author Comment

by:jexd99
ID: 1346065
Thanks for the info on this. I appreciate it. :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now