Mega Code Archive

 
Categories / Delphi / Examples
 

Functionscalledfromstrlisttbl

CALL FUNCTIONS FROM LIST OF FUNCTIONS HELD IN TABLE Folks, I don't know where this topic is at the moment, but here is an example that I have used. The functions/procedures are not internal to the Delphi EXE, but are stored in a Delphi DLL (nearly as good). I have created a list of functions in a table. All the functions have the same parameters and return values. Using this, I can create a function (or procedure definition) in the routine used to call the function, as follows: function CallFunction(const LibraryName, FunctionName: String): Integer; var f: function: Integer; h: THandle; begin { load library } h := LoadLibrary(PChar(LibraryName)); { if library loaded } if h <> 0 then begin try { call function } @f := GetProcAddress(h, PChar(FunctionName)); if @f <> nil then Result := f; { free library } finally FreeLibrary(h); end; end; end; Admittedly, you need to know the structure (parameters and results) of each type of function/procedure you create, but you can define these as a 'type', as follows (see Dynamic Loading - DLL's - in the Delphi help for v4): TReportFunction = procedure(var StartDate, EndDate: TDateTime); You could then store the name of the library and functions in a table, load them dynamically and pass them to the above routine. I do this at a client site, where I have a list or reports in a libary, and to add a new report I simply add a record to the database and send them a new DLL, or a new version of the report DLL that has the new report in it. The calling EXE doesn't need to be touched. I hope this helps, Darren P.S. I too am an ex Clipper developer, and noticed that a few Clipper people seemed to move to Delphi when Nantucket missed the Windows market. I remember fondly the ability to call functions and procedures on the fly, and recently tried to do it in Delphi. I managed to do it for the method of a class, but couldn't find a way to locate the address of a procedure or function. Does anyone know if this is possible, or am I talking bull ? _______________________________________________ Delphi mailing list -> Delphi@elists.org http://elists.org/mailman/listinfo/delphi