[DUG]User defined routines...
Dennis Chuah
dennis_cs_chuah at hotmail.com
Fri Nov 11 11:26:16 NZDT 2005
1. Use an interface or an abstract base class. UserRoutine1 would be
defined in the interface and called by Libraryroutine1. In each
application, you define the implementation / concrete classes that implement
UserRoutine1.
2. You can use method references ... but using interfaces is more flexible.
3. No, don't go down that path - it is a maintenance nightmare!
----- Original Message -----
From: "John Bird" <johnkbird at paradise.net.nz>
To: "'NZ Borland Developers Group - Delphi List'" <delphi at ns3.123.co.nz>
Sent: Friday, November 11, 2005 11:18 AM
Subject: [DUG]User defined routines...
I use several shared/library routines called from different places in
programs. Sometimes in one of these I want to call a further routine which
executes code that is relevant to the parent application only. What is the
best way to do this in Delphi?
for example in other languages I could do:
example -1
Program1 calls Libraryroutine1
Libraryroutine1 calls routine with a fixed name eg UserRoutine1
And I would have several separate source versions of UserRoutine1, one for
each application and the link file for the application would specify whihch
one got linked in, and hence called and executed.
I can't do this in Delphi as the unit itself contains the linking
information in the uses clauses.
example - 2
In other languages I have see code like
Callroutine(routinename,arg1,arg2,arg3.....) where routinename is a string
variable that can be set to the value you want in Application1, and the
Callroutine would then call this routine Routinename with the arguments arg1
arg2 etc (ie the routine name becomes a variable and can be pointed at
different code. Is this possible or recommended in Delphi?
example - 3
This is one way you can do it in Delphi - you have a shared routine
UserRoutine1 containing all the code for all applications that need it....
eg
procedure UserRoutine1...
if ExtractFileName(Application.exename)='Fred.exe' then
begin
....
....
end
if ExtractFileName(Application.exename)='Joe.exe' then
begin
....
....
end
if ExtractFileName(Application.exename)='Bill.exe' then
begin
....
....
end
This works but is very clumsy in that code not relevant to the application
is compiled in, and also objects/forms/globals relevant to one application
are not useable as other applications will not be using them. In some cases
where the UserRoutine is doing very limited local stuff this may be fine, or
limited numbers of these can be passed in as parameters through
LibraryRoutine1 to UserRoutine1.
What is the recommended or most elegant way to do this in Delphi? I am
thinking maybe the easiest is using an include directive to pick up the
relevant library code for LibraryRoutine1 routine directly into the
application unit - which already contains code for UserRoutine1
John
--------------------------------------------------------------------------------
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.co.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi
>
More information about the Delphi
mailing list