Recent

Author Topic: FPC 3.2.2 - AnAddr: CodePointer - How to use for Function call ?  (Read 1708 times)

paule32

  • Sr. Member
  • ****
  • Posts: 280
FPC 3.2.2 - AnAddr: CodePointer - How to use for Function call ?
« on: November 20, 2024, 01:06:22 pm »
Hello,

how the Subject says: How to use CodePointer for calling a Pascal Function ?
Thanks for reading, and helping

paule32

Fibonacci

  • Hero Member
  • *****
  • Posts: 647
  • Internal Error Hunter
Re: FPC 3.2.2 - AnAddr: CodePointer - How to use for Function call ?
« Reply #1 on: November 20, 2024, 01:09:04 pm »
Like this?

Code: Pascal  [Select][+][-]
  1. procedure test;
  2. begin
  3.   writeln('test proc');
  4. end;
  5.  
  6. var
  7.   p: codepointer;
  8.   t: procedure;
  9.  
  10. begin
  11.   // lets say you have a pointer
  12.   p := @test;
  13.  
  14.   // and you want to call it
  15.   // assign pointer to "t"
  16.   pointer(t) := p;
  17.   // and call it
  18.   t;
  19. end.

paule32

  • Sr. Member
  • ****
  • Posts: 280
Re: FPC 3.2.2 - AnAddr: CodePointer - How to use for Function call ?
« Reply #2 on: November 20, 2024, 01:15:06 pm »
thanks fibo !
I am out of hospital, and have more time for our project.
How about you ?
I hope a good mood.

Fibonacci

  • Hero Member
  • *****
  • Posts: 647
  • Internal Error Hunter
Re: FPC 3.2.2 - AnAddr: CodePointer - How to use for Function call ?
« Reply #3 on: November 20, 2024, 01:16:41 pm »
Glad you are ok :) Im fine too, thanks

Ten_Mile_Hike

  • Jr. Member
  • **
  • Posts: 91
Re: FPC 3.2.2 - AnAddr: CodePointer - How to use for Function call ?
« Reply #4 on: November 20, 2024, 06:30:21 pm »
Code: Text  [Select][+][-]
  1. Hello Guys,
  2. Could you help me to understand when any why
  3. Button1Click would be preferred over the Button2Click
  4. procedures below.
  5.  
  6. Thanks,
  7. DBM
  8.  


Code: Pascal  [Select][+][-]
  1. Procedure test;
  2. begin
  3.   Form1.button1.caption:='test proc';
  4. end;
  5.  
  6. procedure TForm1.Button1Click(Sender:TObject);
  7. var
  8.   p: codepointer;
  9.   t: procedure;
  10. begin
  11.   p := @test;
  12.   pointer(t) := p;
  13.   t;
  14. end;
  15.  
  16. procedure TForm1.Button2Click(Sender:TObject);
  17. begin
  18.   Test;
  19. end;
When any government, or any church for that matter, undertakes to say to its subjects, This you may not read, this you
must not see, this you are forbidden to know, the end result is tyranny and oppression no matter how holy the motives.

Robert A. Heinlein

paule32

  • Sr. Member
  • ****
  • Posts: 280
Re: FPC 3.2.2 - AnAddr: CodePointer - How to use for Function call ?
« Reply #5 on: November 20, 2024, 06:41:53 pm »
you need a global object event procedure with the signature as the original event procedure.
then you can bind a event to a procedure, which can be implemented in the implementation part of the module/unit.

and to let call this procedure, you can Assign the event with a simple pointer:

Code: Pascal  [Select][+][-]
  1. onClick := @yourEventProc;

take a look to TNotify.
« Last Edit: November 20, 2024, 06:44:23 pm by paule32 »

 

TinyPortal © 2005-2018