Further to my earlier post I found some of the code I used to call functions
by name at runtime and have put this below.  The basic idea (and the bulk of
the code) for this was given to me by a C programmer.

If anyone has a neater way to access methods at runtime I would love to see
it.

Stephen

In the Application units
-----------------------------------
...
uses dispatch;
...
var
  Req : TStringList;
  LocalVariable : String;
...
  // To call a function - initialize the parameters and call CallFnc
  Req.Clear;
  Req.Add('Param1=XX');
  Req.Add('Param2=1');
  LocalVariable := CallFnc('FunctionName',Req);
...
initialization
  // Add all functions to the FnList
  FnList.AddObject('<FunctionName>=<whatever ID you want to
use>',@FunctionName);
end.


Function calling unit
------------------------------------ 
unit dispatch;

interface

uses Classes, sysutils;

type
   TCallFn = function(req : TStringList) : string;

function CallFnc (FncName : string; Req : TStringList):string;

var
   FnList : tstringlist;

implementation

function CallFnc (FncName : string; Req : TStringList):string;
begin
   if Fnlist.indexofname(FncName) = -1 then
      Result := ' Function ' + FncName + ' not found '
   else
      Result :=  TCallFn (FnList.objects[
FnList.indexofname(FncName)])(Req);
end;

initialization
  FnList := TStringList.Create;
finalization
  FnList.Free;
end.
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to