[DUG] Uses

Sean Cross Sean.Cross at catalystrisk.co.nz
Tue Apr 3 16:11:11 NZST 2007


IMHO rewriting the GeneralFunctions unit for different projects is not the best way to do it.  I do exactly that for some unit tests, but I am not proud of it :(.

There are some design patterns for that sort of thing. OTTOMH either Factory or Strategy patterns are what you are looking for.

Alternately you might want to use Events or method pointers (I forget what they are called in Delphi, but they are like events, but not attached to an object.

Ie something like

In commonstuff.pas
...
type  TDoSomething = procedure(ASTring: string);

var  FDoSomething: TDoSomething;

procedure SetDoSomething(ADoSomething: TDoSomething);
begin
  FDoSomething:= ADoSomething;
end;

procedure DoSomething(AString: string);
begin
  // calls whatever
  if assigned(FDoSomething) then
    FDoSomething(AString)
  Else
    //Oh poo
...
End;

Then in your general functions call

procedure MyDoSomething (AString: string);
begin
...
// actally do your custom actions here
End;

initialization
  SetDoSomething(MyDoSomething);

Regards

Sean Cross
IT Systems Development Manager

Catalyst Risk Management
PO Box 230
50 Dalton St
Napier 4140
DDI: 06-8340362
mobile: 021 270 3466
Visit us at http://www.catalystrisk.co.nz/

Offices in Auckland, Napier, Wellington & Christchurch

Disclaimer:
"The information contained in this document is confidential to the addressee(s) and may be legally privileged. Any view or opinions expressed are those of the author and may not be those of Catalyst Risk Management. No guarantee or representation is made that this communication is free of errors, viruses or interference. If you have received this e-mail message in error please delete it and notify me. Thank you."


> -----Original Message-----
> From: delphi-bounces at ns3.123.net.nz [mailto:delphi-
> bounces at ns3.123.net.nz] On Behalf Of John Bird
> Sent: Tuesday, 3 April 2007 3:52 p.m.
> To: 'NZ Borland Developers Group - Delphi List'
> Subject: [DUG] Uses
>
> I have a standard component thingy from which I want to be able to call
> routines that are specific to one project.
>
> My aim is to centralise some complex functions like data editing or
> printing
> as much as possible in one powerful unit, but still have the shared
> unit
> able to call functionality specific to this project.
>
> I presume the best way to do this is to vary the uses clause for the
> project, using the same function names that exist in different units.
> However the standard component thingy has to have a fixed unit name in
> its
> "uses" clause.
>
> Say the component thingy is called StandardEdit, and calls some
> functions
> called
>
> GeneralLoadData  and GeneralSaveData
>
> The StandardEdit unit would have
>
> "Uses GeneralFunctions" in its uses clause.
>
> I could have several units called GeneralFunctions (in various folders)
> with
> functions called
>
> GeneralLoadData and GeneralSaveData in each of them,
>
> One could be in a folder called DummyGeneral, and each function just
> does
> nothing.  This would be used in cases where the StandardEdit is being
> used
> (but no special functionality is needed in these functions) just to
> satisfy
> the linker.
>
> And others specific to the project could be in the project folder for a
> specific program, with code in each function specific to that project -
> eg
> for project Fred1
>
> "Uses GeneralFunctions in "\src\Fred1\GeneralFunctions.pas"
>
> Which one gets linked in to a particular program depends on the DPR
> which
> defines which SharedFunctions unit is actually included in this
> project.
>
> Question - is this the best way to call specific tailored routines from
> a
> standard shared unit, or is there another better way I have missed?
>
>
> John
>
>
> _______________________________________________
> Delphi mailing list
> Delphi at ns3.123.net.nz
> http://ns3.123.co.nz/mailman/listinfo/delphi



More information about the Delphi mailing list