Recent

Author Topic: Something is wrong with this code, but I can't decide what it is  (Read 1759 times)

paweld

  • Hero Member
  • *****
  • Posts: 1434
Re: Something is wrong with this code, but I can't decide what it is
« Reply #15 on: May 26, 2025, 12:04:30 pm »
@440bx: Looks like Consolas. Some fonts for comparison: https://forum.lazarus.freepascal.org/index.php/topic,70446.msg549165.html#msg549165
Best regards / Pozdrawiam
paweld

ALLIGATOR

  • Full Member
  • ***
  • Posts: 195
Re: Something is wrong with this code, but I can't decide what it is
« Reply #16 on: May 26, 2025, 12:11:02 pm »
Never thought about it, the default font

Thaddy

  • Hero Member
  • *****
  • Posts: 17441
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: Something is wrong with this code, but I can't decide what it is
« Reply #17 on: May 26, 2025, 12:46:12 pm »
What I meant is:
Code: Pascal  [Select][+][-]
  1. {$mode objfpc}
  2. {$modeswitch functionreferences}
  3. type
  4.   TProcedureRef = reference to Procedure;
  5.   procedure hello;
  6.   begin
  7.     writeln('hello');
  8.   end;;
  9. var
  10.   p:TProcedureRef;
  11. begin
  12.   p:=@hello;// maybe mode delphi accepts: p:=hello()
  13.   p();
  14. end.
Untested.
« Last Edit: May 26, 2025, 12:56:40 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

440bx

  • Hero Member
  • *****
  • Posts: 5589
Re: Something is wrong with this code, but I can't decide what it is
« Reply #18 on: May 26, 2025, 12:55:43 pm »
Thank you @paweld and
Thank you ALLIGATOR.

That font looked quite readable, for that reason I wanted to know which one it was.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 17441
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: Something is wrong with this code, but I can't decide what it is
« Reply #19 on: May 27, 2025, 10:21:40 am »
@ALLIGATOR
Answer to original question:
Code: Pascal  [Select][+][-]
  1. program project1;
  2. {$ifdef fpc}
  3. {$mode delphi}
  4. {$modeswitch anonymousfunctions}
  5. {$modeswitch functionreferences}
  6. {$endif}
  7. type
  8.   TMyProc = reference to procedure (value: NativeInt); // <<------reference----
  9.  
  10. procedure Test(const anonproc:TMyProc);
  11. begin
  12.   anonproc(33);
  13. end;
  14.  
  15. procedure Run;
  16. begin
  17.   Test(procedure (value: NativeInt)
  18.        begin
  19.          WriteLn('Anon value = ', value);
  20.        end);
  21. end;
  22.  
  23. begin
  24.   Run;
  25.   ReadLn;
  26. end.

Small change, but that is what I meant: it should be a reference.
Btw: highly contrived code you wanted, but it works now.

This is actually another example of combining anonymous methods and function references similar to what I gave last week.
« Last Edit: May 27, 2025, 05:12:01 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018