Structuring a unit of supplemental procedures and functions in Delphi

Posted on 2009-04-19
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
    LVL 6

    Expert Comment

    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 36

    Assisted Solution

    by:Geert Gruwez
    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

    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

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
    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…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    746 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

    17 Experts available now in Live!

    Get 1:1 Help Now