I have a problem. I want call my functions in pascal by their names
stored in an array for example.. (array[1..n] of string).. i want the
same of PHP call_user_func function.. or something near that.. Is
there any way to do this?
thanks,
Eureka
Which Pascal exactly? This is .misc?
I want to make this in Borland Pascal 7.
The code that Marco posted in the other thread works, if augmented by
some "red tape" in BP7 (interestingly not in native FreePascal, you
have to use Delphi mode). Here the complete code and execution
example:
program pp;
procedure proc1(i:integer);
begin
writeln('proc1:',i);
end;
procedure proc2(i:integer);
begin
writeln('proc2:',i);
end;
Type
TProcType = procedure (i:integer);
TProcCombo = record
name:string;
prc :TProcType;
end;
const nn: array[0..1] of TProcCombo =
((name:'proc1';prc:proc1),(name:'proc2';prc:proc2));
var
s: string;
i,cnt: integer;
begin
cnt := 0;
repeat
readln(s);
inc(cnt);
if s='' then break;
for i:=0 to 1 do begin
if s=nn[i].name then begin
nn[i].prc(cnt);
break;
end;
end;
until false;
end.
C:\TMP>bpc -b PP.PAS
Borland Pascal Version 7.0 Copyright (c) 1983,92 Borland
International
PP.PAS(39)
39 lines, 3008 bytes code, 1450 bytes data.
C:\TMP>pp
pco1
proc1
proc1:2
proc2
proc2:3
proc3
proc1
proc1:5
--
In order to e-mail me a reply to this message, you will have
to remove PLEASE.REMOVE from the address shown in the header
or get it from http://home.netsurf.de/wolfgang.ehrhardt
(Free open source Crypto, AES, CRC, Hash for Pascal/Delphi)
The example as you printed it works in TP and Delphi modes, for FPC modes
you have to add "@" before proc1 and proc2 in the constant. The need for
this @ disambiguator is a typical feature of FPC modes.