Learn how to a build a cloud-first strategyRegister Now


Structuring a unit of supplemental procedures and functions in Delphi

Posted on 2009-04-19
Medium Priority
Last Modified: 2012-05-06
The main form of an application was becoming overly large so I wanted to move some of the procs/functions to a supplemental unit.  I have done this and the application compiles and runs properly.  However, when I am in the main form and ctrl-click on the name of a procedure that is defined in the supplemental unit the cursor jumps to the top of the supplemental unit where the procedure is declared but does not move to the procedure code as it does if the proc is defined in the main form or another form.

I want to know if this is a limitation of the development environment or am I not properly structuring my unit of supplemental procs and functions?  (see code segments showing head of each file).

MAIN FORM - - - - - -
unit AppMain;
  . . . 
  TfrmMain = class(TForm)
  . . .
  frmMain: TfrmMain;
uses . . . AppGenProcs;
  . . .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
SUPPLEMENTAL UNIT - - - - - - - -
unit AppGenProcs;
  Classes, SysUtils, Math;
procedure CaseStageChange(NewStage: Byte);
procedure CopyResultsGridToSourceFields;
uses AppMain;
procedure CaseStageChange(NewStage: Byte);
  . . .
  . . .

Open in new window

Question by:ttheimer

Expert Comment

ID: 24181353
I've found that sometimes Delphi forgets the linkages there. Usually, the "ctrl-click" link can be restored when you do a full build (as opposed to a compile).   Well, at least for me that's true....  :)

LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 200 total points
ID: 24182418
you should try to create helper units which do not need the mainform unit
by using parameters in the headers of the procs

this way you will not have circular references
LVL 22

Accepted Solution

8080_Diver earned 800 total points
ID: 24201092
Do you have all of your data access component on the Main FOrm?  If so, then you should move those and the associated functions/procedures for accessing the data to a DataModule.
Also, as pointed out above, you need to decouple the auxiliary units from the  main unit.  That is the whole idea of reusable code and modular/unit design.  You may have to slightly redesign some of you functions and procedures so that you pass them variables instead of having them directly snatch values from edit controls on the main form or having them use private/publix objects within the MainFrom's declaration.

If you have functions/procedures in your Supplemental Unit that do not receive parameters and, instead, directly access things in the main unit, you have what is called a closely coupled unit.  It is chained to the main unit.  If, on the other hand, you change it so that the various functions and procedures are passed parameters, you will probably find that you have less confusion over what is being used and how in the main unit.  
For instance, I have an AboutBox that I frequently use in my applications.  It is completely decoupled from any applications because it has its own public function (i.e. one that is not at all a part of the TWGAboutBox class) that activates the AboutBox and handles the setting up of the various captions, etc..  This lets me pass parameters (whether constants or variables) from my main app and have the AboutBox pop up with all its functionality.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month20 days, 23 hours left to enroll

810 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