Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Call custom function in pascal

1 view
Skip to first unread message

Eureka

unread,
Feb 21, 2009, 2:16:46 PM2/21/09
to
Hey guys,

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

Marco van de Voort

unread,
Feb 22, 2009, 7:20:06 AM2/22/09
to

Which Pascal exactly? This is .misc?

Eureka

unread,
Feb 23, 2009, 10:55:24 AM2/23/09
to
On Feb 22, 1:20 pm, Marco van de Voort <mar...@stack.nl> wrote:

I want to make this in Borland Pascal 7.

Wolfgang Ehrhardt

unread,
Feb 23, 2009, 12:20:25 PM2/23/09
to
On Mon, 23 Feb 2009 07:55:24 -0800 (PST), Eureka
<bandi...@gmail.com> wrote:

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)

Marco van de Voort

unread,
Feb 23, 2009, 2:40:37 PM2/23/09
to
On 2009-02-23, Wolfgang Ehrhardt <Wolfgang.Ehrhar...@munich.netsurf.de> wrote:
> On Mon, 23 Feb 2009 07:55:24 -0800 (PST), Eureka
><bandi...@gmail.com> wrote:
>
>>On Feb 22, 1:20=A0pm, Marco van de Voort <mar...@stack.nl> wrote:
>>> On 2009-02-21, Eureka <bandi.to...@gmail.com> wrote:
>>>
>>> > 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?
>>>
>>> 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).

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.

0 new messages