Forum > Networking and Web Programming
Http Server
michoux:
Thanks.
How do I call TWebServerThread.Execute from my app?
PierceNg:
--- Quote from: michoux on December 05, 2022, 01:59:15 pm ---How do I call TWebServerThread.Execute from my app?
--- End quote ---
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---begin // Set up web server. fphttpapp.Application.Port := 8000; fphttpapp.Application.Threaded := true; // web server itself is multi-threaded fphttpapp.Application.Initialize; // Run the server in a thread. // If you want to start the server on button press, then move next line to the button press handler. TWebServerThread.Create(false); // false means the server thread runs immediately // Now run LCL application. RequireDerivedFormResource:=True; Forms.Application.Scaled:=True; Forms.Application.Initialize; Forms.Application.CreateForm(TForm1, Form1); Forms.Application.Run; end.
See https://wiki.freepascal.org/Multithreaded_Application_Tutorial for more info.
michoux:
Thank you very much.
I inserted form on which I have a report with lazReport.
After I get response from a webserver I want to call to open report, which is on form1 which I added.
I use
form1.frReport1.ShowReport;
This kills my app with SIGSERV ...
Is this related to thred?
PierceNg:
--- Quote from: michoux on December 05, 2022, 03:42:02 pm ---Thank you very much.
I inserted form on which I have a report with lazReport.
After I get response from a webserver I want to call to open report, which is on form1 which I added.
I use
form1.frReport1.ShowReport;
This kills my app with SIGSERV ...
Is this related to thred?
--- End quote ---
Dunno. If you post a simplified but complete project that compiles and demonstrates the crash, then others will be better placed to help.
michoux:
Here is simple code.
I also have a form with lazreport on it this is all.
I just want to open report with
form1.frReport1.LoadFromFile('test.lrf');
form1.frReport1.ShowReport;
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- program Project1; {$mode objfpc}{$H+} uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} Classes,SysUtils, fphttpapp, httpdefs, httproute, fpjson, jsonparser, interfaces,forms,Unit1; type TWebServerThread = class(TThread) protected procedure Execute; override; public constructor Create(CreateSuspended: boolean); end; constructor TWebServerThread.Create(CreateSuspended: boolean); begin inherited Create(CreateSuspended); FreeOnTerminate := true; end; procedure TWebServerThread.Execute; begin fphttpapp.Application.Run; end; procedure test(req: TRequest; res: TResponse);var s:string; rawJson: AnsiString; people: TJSONArray; person: TJSONObject; personEnum: TJSONEnum;begin // Get the JSON data rawJson:=req.Content; writeln(rawjson); form1.frReport1.LoadFromFile('test.lrf'); form1.frReport1.ShowReport;end; begin fphttpapp.Application.Port := 8000; HTTPRouter.RegisterRoute('/test', @test, true); fphttpapp.Application.Threaded := true; fphttpapp.Application.Initialize; TWebServerThread.Create(false); RequireDerivedFormResource:=True; Forms.Application.Scaled:=True; Forms.Application.Initialize; Forms.Application.CreateForm(TForm1, Form1); Forms.Application.Run; end.
Navigation
[0] Message Index
[#] Next page
[*] Previous page