Maxbe 'stupid' ... But I'm dealing with it !
---------------------------------------- Type ptrRecord = ^theRecord; Type theRecord = record move : ProcPtr; hit : ProcPtr end;
Procedure moveIt; Begin end;
Procedure hitIt; Begin end;
Procedure Init; Begin object^.move := @moveIt; object^.hit := @hitIt end;
Procedure Run; Begin repeat with object^ do ???? Until ... End; ----------------------------------------
HOW can I make the actions point to moveIt and hitIt ?
HOW is it possible to call the ProcPtr's procedures (Osx.3, GNU pascal) ?
If you can help me, thank you !
Alain
Alain a écrit:
Maxbe 'stupid' ... But I'm dealing with it !
Type ptrRecord = ^theRecord; Type theRecord = record move : ProcPtr; hit : ProcPtr end;
Procedure moveIt; Begin end;
Procedure hitIt; Begin end;
Procedure Init; Begin object^.move := @moveIt; object^.hit := @hitIt end;
Procedure Run; Begin repeat with object^ do ???? Until ... End;
The following progral compiles and runs as you expect
------------------------------------------------------------ program test;
type ProcPtr = procedure;
Type theRecord = record move : ProcPtr; hit : ProcPtr end; Type ptrRecord = ^theRecord;
var obj: ptrRecord;
Procedure moveIt; Begin writeln('move') end;
Procedure hitIt; Begin writeln('hit') end;
Procedure Init; Begin obj^.move := moveIt; obj^.hit := hitIt end;
Procedure Run; Begin with obj^ do begin move; hit end End;
begin new(obj); init; run; dispose(obj); end. -----------------------------------------------------------
The problem was with unnecessary @ A confusion with C syntax, I suppose
Maurice
Alain a écrit:
Maxbe 'stupid' ... But I'm dealing with it !
Type ptrRecord = ^theRecord; Type theRecord = record move : ProcPtr; hit : ProcPtr end;
Procedure moveIt; Begin end;
Procedure hitIt; Begin end;
Procedure Init; Begin object^.move := @moveIt; object^.hit := @hitIt end;
Procedure Run; Begin repeat with object^ do ???? Until ... End;
An afterthought. The following program which uses objects instead of records (this was your goal as I suppose from your naming) compiles and run also
--------------------------------------------------------------- program test;
type ProcPtr = procedure;
Type theObject = object constructor init; move : ProcPtr; hit : ProcPtr end; Type ptrObject = ^theObject;
var obj: ptrObject;
Procedure moveIt; Begin writeln('move') end;
Procedure hitIt; Begin writeln('hit') end;
constructor theObject.Init; Begin move := moveIt; hit := hitIt end;
Procedure Run; Begin with obj^ do begin move; hit end End;
begin new(obj,init); run; dispose(obj); end. ---------------------------------------------------------------
this is interesting because I read recently in a Borland Delphi discussion group that pointers to ordinary procedure and pointer to class methods are essentially different things, so that such a construct, that the user was trying to implement, was impossible. He was asking: how to use a "static procedure" as an "object method". This may be not really different because move and hit are declared here as ProcPtr, not as methods (i.e. with "procedure move;" ...). The problem will come if one tries to declare move as "virtual". This is not possible here because move is a variable, not a procedure. This at least gives a workaround for some problems. An other would be probably to declare move as "procedure move" and use it as a wrapper to call internally a "static procedure". But you will probably have to think more carefully on why you try to implement such "C minded" constructs.
Maurice
Maurice Lombardi wrote:
this is interesting because I read recently in a Borland Delphi discussion group that pointers to ordinary procedure and pointer to class methods are essentially different things, so that such a construct, that the user was trying to implement, was impossible. He was asking: how to use a "static procedure" as an "object method".
Yes, object methods (whether virtual or not) have the hidden `Self' parameter, so they're not exchangeable with non-method routines with the same arguments.
Frank