Recent

Author Topic: SOLVED PHPEval  (Read 874 times)

ADMGNS

  • New Member
  • *
  • Posts: 46
  • keep it simple and smart
SOLVED PHPEval
« on: May 03, 2025, 04:34:49 pm »
hello

i,m trying to use PHP library functions in D7 and Lazarus.

it works fine in D7, but not in Lazarus. it compiles but not runs, ie terminates with an exception.

thanks
https://www.dropbox.com/scl/fo/i393lw9j1ugm5dntg443q/APeuLhfVqVhVpxIXs90OQjo?rlkey=l278lzv5v76xbvy6bk0l7m76h&st=rdox67ht&dl=0
« Last Edit: May 09, 2025, 03:25:18 am by ADMGNS »

Thaddy

  • Hero Member
  • *****
  • Posts: 17388
  • Ceterum censeo Trump esse delendam
Re: PHPEval
« Reply #1 on: May 03, 2025, 05:02:00 pm »
Declare all strings explicitly as AnsiString, not string. D7 uses AnsiString as the default string type, Lazarus - not fpc - mutilates them into UTF8, which is usually not bad, but here it is.
It is a simple search and replace. And keeps it D7 compatible!
(Also it requires mode delphi, but you are aware of that.)
« Last Edit: May 03, 2025, 05:06:50 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

ADMGNS

  • New Member
  • *
  • Posts: 46
  • keep it simple and smart
Re: PHPEval
« Reply #2 on: May 03, 2025, 05:11:57 pm »
hello thaddy

just tried but same result..

is it the same as D7 using exported funcs from a dll, in Laz? i think so.

??

thanks

ADMGNS

  • New Member
  • *
  • Posts: 46
  • keep it simple and smart
Re: PHPEval
« Reply #3 on: May 03, 2025, 05:43:06 pm »
hello again

could you convert the project (PHPEval.D7.7z) to Laz and share back, from above link?

thank you

 

Fibonacci

  • Hero Member
  • *****
  • Posts: 786
  • Internal Error Hunter
Re: PHPEval
« Reply #4 on: May 03, 2025, 06:39:35 pm »

ADMGNS

  • New Member
  • *
  • Posts: 46
  • keep it simple and smart
Re: PHPEval
« Reply #5 on: May 03, 2025, 07:24:19 pm »
hello,  is this (screenshot) D7 or Laz?


Fibonacci

  • Hero Member
  • *****
  • Posts: 786
  • Internal Error Hunter
Re: PHPEval
« Reply #6 on: May 03, 2025, 07:25:00 pm »
Lazarus. Make sure you compile for Win32 - i386.

Oh.. This is it, I didnt check your binaries before. DLLs are 32 bit, and your EXE binary is 64 bit.
« Last Edit: May 03, 2025, 07:28:39 pm by Fibonacci »

ADMGNS

  • New Member
  • *
  • Posts: 46
  • keep it simple and smart
Re: PHPEval
« Reply #7 on: May 03, 2025, 07:29:40 pm »
OK, thanks..

that is the problem.. sorry.. i,ve jumped, i,ve missed it :-[

Thaddy

  • Hero Member
  • *****
  • Posts: 17388
  • Ceterum censeo Trump esse delendam
Re: PHPEval
« Reply #8 on: May 03, 2025, 10:27:14 pm »
I see on the php website that there are versions for X64 available too.
The version (8.x) is probably too new for phpfordelphi or phpforlazarus that are for 4/5
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

ADMGNS

  • New Member
  • *
  • Posts: 46
  • keep it simple and smart
SOLVED Re: PHPEval
« Reply #9 on: May 09, 2025, 03:23:26 am »
hello,

the problem,s solved.. but, yes, you are right.. it is very old..

following is another solution, but not open source

https://blogs.embarcadero.com/world-famous-native-windows-php-ide-is-built-in-delphi/

Thaddy

  • Hero Member
  • *****
  • Posts: 17388
  • Ceterum censeo Trump esse delendam
Re: SOLVED PHPEval
« Reply #10 on: May 09, 2025, 11:57:56 am »
Yes, but it is free and I have it installed.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Thaddy

  • Hero Member
  • *****
  • Posts: 17388
  • Ceterum censeo Trump esse delendam
Re: SOLVED PHPEval
« Reply #11 on: May 09, 2025, 12:00:17 pm »
Oh and a poor man's solution:
Code: Pascal  [Select][+][-]
  1. program pythonchecker;
  2. {$mode objfpc}{$I-}{$H+}{$ifdef mswindows}{$apptype console}{$endif}
  3. uses sysutils,classes, process;
  4. type
  5. { TProcessEx }
  6. TProcessEx = class(TProcess)
  7. private
  8.   FStartTime,FLoadTime:Int64;
  9. protected
  10.   procedure SysExecute;override;
  11. public
  12.   constructor create(Aowner:TComponent);override;
  13.   procedure CheckLoading(Sender: TObject;Context: TObject;
  14.                  Status: TRunCommandEventCode;const Message: string);
  15.   property LoadTime:Int64 read FLoadTime;
  16. end;
  17.  
  18. { TProcessEx }
  19. constructor TProcessEx.create(Aowner: TComponent);
  20. begin
  21.   inherited create(Aowner);
  22.   OnRunCommandEvent := @CheckLoading;
  23. end;
  24.  
  25. procedure TProcessEx.SysExecute;
  26. begin
  27.   FStartTime := GetTickCount64;
  28.   FLoadTime := 0;
  29.   inherited SysExecute;
  30. end;
  31.  
  32.  
  33. procedure TProcessEx.CheckLoading(Sender: TObject; Context: TObject;
  34.   Status: TRunCommandEventCode; const Message: string);
  35. begin
  36.   if (LoadTime = 0) then
  37.   begin
  38.     { first time the event fires }
  39.     FLoadTime :=GetTickCount64-FStartTime;
  40.     writeln(LoadTime,'ms load time ',Status);
  41.    end;
  42. end;
  43.  
  44. var
  45.  P:TProcess;
  46.  a,b:string;
  47.  c:integer;
  48.  
  49. (*
  50. import json
  51. from jsonschema import validate
  52. from jsonschema.exceptions import ValidationError
  53. with open("./recipes.json") as f:
  54.    document = json.load(f)
  55. with open("./recipes_schema.json") as f:
  56.    schema = json.load(f)
  57. try:
  58.    validate(instance=document, schema=schema)
  59.    print("Validation Succeeded!")
  60. except ValidationError as e:
  61.    print('Validation failed !')
  62.    print(f"Error message: {e.message}")
  63. *)
  64. begin
  65.  P :=TProcessEx.Create(nil);
  66.  try
  67.    P.executable:='python3';
  68.    P.Parameters.Add('-m');
  69.    P.Parameters.Add('py_compile');
  70.    P.Parameters.Add('hello2.py');
  71.    P.Options :=[poUsePipes,poRunIdle];
  72.    P.RunCommandLoop(a,b,c);
  73.    writeln('------stdOut-----------');
  74.    writeln(a);
  75.    writeln('------stdErr-----------');
  76.    writeln(b);
  77.    writeln('------status-----------');
  78.    writeln(c);
  79.    readln;
  80.  finally
  81.    P.Free;
  82.  end;
  83. end.
Very usuable for checking syntax.
hello2.py:
Code: Python  [Select][+][-]
  1. import json
  2. from jsonschema import validate
  3. from jsonschema.exceptions import ValidationError
  4. with open("./recipes.json") as f:
  5.    document = json.load(f)
  6. with open("./recipes_schema.json") as f:
  7.    schema = json.load(f)
  8. try:
  9.    validate(instance=document, schema=schema)
  10.    print("Validation Succeeded!")
  11. except ValidationError as e:
  12.    print('Validation failed !')
  13.    print(f"Error message: {e.message}")
The above succeeds of course, but try making a syntax error in it.

 
« Last Edit: May 09, 2025, 12:08:22 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

 

TinyPortal © 2005-2018