Board index » delphi » Please help me to call procedures....

Please help me to call procedures....

How do i put the adresses of procedures into an array and call them again or
is there another way of doing this. Please help me because this is driving
me crazy.

Thanks in advance.

 

Re:Please help me to call procedures....


Quote
Pjc wrote:

> How do i put the adresses of procedures into an array and call them again or
> is there another way of doing this. Please help me because this is driving
> me crazy.

Oh yes, I see... My first answers were simply not appropriate...

You can of course define a procedural type:
  Type TProc = Procedure(S:String;V : Integer);
and build an array of TProc.
       AProc = Array[0..15] of TProc;

Var ProcList : AProc;

Procedure DoSomething(.....);
Begin
...
End;
Procedure AskSomething(....);
....
  ProcList[12] := DoSomething;
  ProcList[15] := AskSomething;
....
  ProcList[12]('Hallo',-5);
  ProcList[15]('found',10000);
Why not?

But of course it is easyer and more flexible and more efficient
to make an array of objects (or Pobjects) containing methods.
--
Franz Glaser, Glasau 3, A-4191 Vorderweissenbach Austria ++43-7219-7035
Muehlviertler Elektronik Glaser. Industrial control and instrumentation
-----------------------------------------------------------------------
http://members.eunet.at/meg-glaser           mailto:meg-gla...@eunet.at
http://www.geocities.com/~franzglaser  http://members.xoom.com/f_glaser

Re:Please help me to call procedures....


The trick is to make the procedures "far".

For example:

var
a : array[0..2] of procedure(w:word);

procedure p0(i:word); far;
begin
writeln('p0 i=',i);
end;

procedure p1(j:word); far;
begin
writeln('p1 j=',j);
end;

procedure p2(k:word); far;
begin
writeln('p2 k=',k);
end;

Begin

a[0]:=p0;
a[1]:=p1;
a[2]:=p2;

a[0](3);
a[1](7);
a[2](13);

End.

Good Luck.

In article <7c3ode$iv...@newnews.global.net.uk>,
  "Pjc" <P...@globalnet.co.uk> wrote:

Quote
> How do i put the adresses of procedures into an array and call them again or
> is there another way of doing this. Please help me because this is driving
> me crazy.

> Thanks in advance.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Re:Please help me to call procedures....


The trick is to make the procedures "far".

For example:

var
a : array[0..2] of procedure(w:word);

procedure p0(i:word); far;
begin
writeln('p0 i=',i);
end;

procedure p1(j:word); far;
begin
writeln('p1 j=',j);
end;

procedure p2(k:word); far;
begin
writeln('p2 k=',k);
end;

Begin

a[0]:=p0;
a[1]:=p1;
a[2]:=p2;

a[0](3);
a[1](7);
a[2](13);

End.

Good Luck.

In article <7c3ode$iv...@newnews.global.net.uk>,
  "Pjc" <P...@globalnet.co.uk> wrote:

Quote
> How do i put the adresses of procedures into an array and call them again or
> is there another way of doing this. Please help me because this is driving
> me crazy.

> Thanks in advance.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    

Re:Please help me to call procedures....


Quote
Pjc wrote:
> How do i put the adresses of procedures into an array and call them
> again or
> is there another way of doing this. Please help me because this is
> driving
> me crazy.

     What do you REALLY want to do?  It sounds like you want to execute
one of a number of procedures, depending on some (small integer)
parameter.  Why not use a
CASE statement, and call the procedures directly?

     CASE option OF
       1 : doprocedure1;
       2 : doprocedure2;
       etc: doprocedureetc
     END;

[Note -- there is no "etc", I'm just being "generic" here ...]

Bob Schor
Pascal Enthusiast

Re:Please help me to call procedures....


Quote
Bob Schor wrote in message <36E8394C.9BCEA...@vms.cis.pitt.edu>...
>Pjc wrote:

>> How do i put the adresses of procedures into an array and call them
>> again or
>> is there another way of doing this.

>     What do you REALLY want to do?  It sounds like you want to execute
>one of a number of procedures, depending on some (small integer)
>parameter.  Why not use a
>CASE statement, and call the procedures directly?

>Bob Schor
>Pascal Enthusiast

What I REALLY want to do is make a array of TForm (i have made custom
version for graph mode.. its nothing to do with TV) captions and the
appropriate close procedures for the object i.e.

Type
    TGeneric = Record
        Caption : String;
        CloseProc : Procedure; {or whatever}
        end;

var
        Thing : Array [1..4] of TGeneric;
        Form1 : TForm;

Procedure TForm.SomthingInsideObject;
Begin
Thing[1].Caption := TForm.Caption; {i have a proc called caption that
returns the title}
Thing[1].CloseProc := @TForm.Close;
End;

Any ideas?

Other Threads