Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to use Local Routines or Nested Routines Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
19-Jun-03
Category
Algorithm
Language
Delphi 2.x
Views
88
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Raghunath Dhungel

How to declare Local routines in delphi ?

Answer:

It is possible to declare local procedures or Functions within a procedure or 
function. Though it seems some how unusual at the first glance to declare Local 
routines within a routine, it is efficient to do this. If we do not need them 
anywhere other than the routine, why should make them public even within the unit ? 
Let us place them in their proper place, proper routines in proper place ! 

We declare local variables, constants and types before the BEGIN statement of a 
function or procedure. We can also include local routines here. Though it is 
efficient to include local routines here, but, in practice, very few delphi 
programmers use these techniques. 

Example: 
1   
2   procedure PublicProc(p1: TypeofP1; p2: TypeofP2; ....pn: TypeOfPn);
3   var
4     v1: TypeofV1;
5     V2: TypeofV2;
6     .....
7     Vn: TypeofVn;
8   const
9     c1: TypeofC1;
10    {  ............ }
11    {  ............ }
12  
13    procedure LocalProcedure1(p1: TypeofP1; p2: TypeofP2; ....pn: TypeOfPn);
14    var
15      {  ............ }
16      {  ............ }
17    begin
18      {  ............ }
19      {  ............ }
20    end;
21    procedure LocalProcedure2(p1: TypeofP1; p2: TypeofP2; ....pn: TypeOfPn);
22    var
23      {  ............ }
24      {  ............ }
25    begin
26      {  ............ }
27      {  ............ }
28    end;
29    function LocalFunction1(p1: TypeofP1; p2: TypeofP2; ....pn: TypeOfPn): ResultType;
30    var
31      {  ............ }
32      {  ............ }
33    begin
34      {  ............ }
35      {  ............ }
36      result := {..... }
37    end;
38    function LocalFunction2(p1: TypeofP1; p2: TypeofP2; ....pn: TypeOfPn): ResultType;
39    var
40      {  ............ }
41      {  ............ }
42    begin
43      {  ............ }
44      {  ............ }.
45      result := {..... }
46    end;
47  
48  begin {PublicProc}
49    ...........
50      '''''''''''
51      LocalProcedure1(...., ...., ....);
52      ...........
53      LocalProcedure2(...., ...., ....);
54      ...........
55      v1 := LocalFunction1(...., ...., ....);
56      ...........
57      v2 := LocalFunction2(...., ...., ....);
58      ...........
59      ''''''
60  end; {PublicProc}


In this example, the scope of the nested routines 
LocalProcedure1, 
LocalProcedure2, 
LocalFunction1 and 
LocalFunction2   
is limited only to PublicProc. No other routines in the same unit or in other 
units can see them. 

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC