Board index » delphi » Macro function calling

Macro function calling

Another lost post forces me to repost this...

I would like to execute a function via "macro expansion"... any
ideas?  It should work in theory like this:

var
  FuctionToCall: ^function;

function DefineFunctionToCall()
begin
  FunctionToCall := @MyFunction(parameter_list);
end;

function CallTheFunction(params)
begin
  Call FunctionToCall(params);
end;

function Main()
begin
  FunctionToCall();
  CallTheFunction(param_list);
end;

I know this is the right idea, but I can't seem to get the
syntax down... any ideas?

-Dave
--
-=[ dave @ delbruck.pharm.sunysb.edu ]=-

 

Re:Macro function calling


        Not sure exactly what you're trying to do but this may show you how
to do it anyway:

unit Unit1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  THmm = function:byte;

var
  Form1: TForm1;

function AnotherFunction:byte;

implementation

{$R *.DFM}
function OneFunction:byte;far;
begin
result:=1;
end;

function AnotherFunction:byte;
begin
result:=2;
end;

procedure TForm1.Button1Click(Sender: TObject);
var F:THmm;
begin

   if Length(Edit1.Text)>5 then @F:=@OneFunction
      else @F:=@AnotherFunction;

   canvas.textout(10,10,inttostr(F));
end;

end.

        Note that you can explicitly declare the function as far or you can
accomplish the same thing by including it in the interface section - if I
don't do either one I get a GPF.

--
David Ullrich
Don't you guys find it tedious typing the same thing
after your signature each time you post something?
I know I do, but when in Rome...

Other Threads