Solved

Delphi Programming question

Posted on 1997-09-23
4
175 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

12 Experts available now in Live!

Get 1:1 Help Now