Recent

Author Topic: Sending strings from PHP to a freepascal lazarus executable  (Read 9096 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
Sending strings from PHP to a freepascal lazarus executable
« on: January 11, 2018, 04:13:04 pm »
Hey! Does anybody have a URL / Example code for how to exchange strings from a PHP thread on a Raspberry to a lazarus executable ? Or a name for a component set?

Greets, Wouter van Wegen

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Sending strings from PHP to a freepascal lazarus executable
« Reply #1 on: January 11, 2018, 04:31:21 pm »
Hey! Does anybody have a URL / Example code for how to exchange strings from a PHP thread on a Raspberry to a lazarus executable ? Or a name for a component set?

Maybe write a PHP extension in Pascal?

https://en.wikipedia.org/wiki/Php4delphi

Maybe supply more detail here. Why PHP? What's it used for? That sort of thing.


Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Sending strings from PHP to a freepascal lazarus executable
« Reply #2 on: January 11, 2018, 07:18:30 pm »
Depends on how they communicate each other. You can use PHP's built-in exec, Pascal executable will just receive it as normal command line parameters.

balazsszekely

  • Guest
Re: Sending strings from PHP to a freepascal lazarus executable
« Reply #3 on: January 11, 2018, 10:23:28 pm »
Basic communication:
1. PHP - Save as lazarus.php, copy to your local server:
Code: PHP  [Select][+][-]
  1. <?php
  2.   $a=$_POST['a'];
  3.   $b=$_POST['b'];
  4.   echo $a + $b;
  5. ?>
2. Lazarus - Create a new project, add a TButton, create OnClick event:
Code: Pascal  [Select][+][-]
  1. uses fphttpclient;
  2.  
  3. procedure TForm1.Button1Click(Sender: TObject);
  4. var
  5.   FPHTTPClient: TFPHTTPClient;
  6.   SL: TStringList;
  7.   Str: String;
  8. begin
  9.   FPHTTPClient := TFPHTTPClient.Create(nil);
  10.   try
  11.     FPHTTPClient.AllowRedirect := True;
  12.     SL := TStringList.Create;
  13.     try
  14.       SL.Add('a=' + IntToStr(9));
  15.       SL.Add('b=' + IntToStr(6));
  16.       try
  17.         Str := FPHTTPClient.SimpleFormPost('http://localhost/lazarus.php', SL);
  18.         ShowMessage(Str);
  19.       except
  20.         on E: exception do
  21.           ShowMessage(E.Message);
  22.       end;
  23.     finally
  24.       SL.Free;
  25.     end;
  26.   finally
  27.     FPHTTPClient.Free;
  28.   end;
  29. end;  

 

TinyPortal © 2005-2018