[Solved] Create a web server in a different Unit lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- SKBotNL · 2023-05-14 10:00 Hello, I have a Forms application and I want to add a webserver to it, but when I want to for example set a port I need to use Application.Port, which doesnt exist when I'm creating a forms application. When adding "fphttpapp" to the uses other properties break. What can I do? ---------------------------------------------------------------------- SKBotNL · 2023-05-14 11:44 Yet another one I finally fixed myself. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program simplehttpserver; {$mode objfpc}{$H+}{$define UseCThreads} uses  cthreads, sysutils, Classes, fphttpserver; Type   { TTestHTTPServer }   TTestHTTPServer = Class(TFPHTTPServer)  public    procedure HandleRequest(Var ARequest: TFPHTTPConnectionRequest;                          Var AResponse : TFPHTTPConnectionResponse); override;   end; Var  Serv : TTestHTTPServer;{ TTestHTTPServer } procedure TTestHTTPServer.HandleRequest(var ARequest: TFPHTTPConnectionRequest;  var AResponse: TFPHTTPConnectionResponse);begin  AResponse.Content := 'hi';  AResponse.SendContent;end; begin  Serv:=TTestHTTPServer.Create(Nil);  try    Serv.Threaded:=False;    Serv.Port:=8080;    Serv.AcceptIdleTimeout:=1000;    Serv.Active:=True;  finally    Serv.Free;  end;end.This doesn't use "Applications" so it's way easier to implement in a Unit. ---------------------------------------------------------------------- Leledumbo · 2023-05-17 06:19 There's Application object in these units: FormsFPHTTPAppFPHTTPSysFPFCGIFPCGISo if you want to access each, you must qualify with the unit name such as: Forms.Application, fphttpapp.Application and so on. The problem is that each Application is also designed as an event loop consumer than runs synchronously on the call of its .Run method. Therefore, you will also need to make both the call asynchronous as well as providing a replacement "wait" mechanism that waits for all .Run methods to finish, like so (WARNING: untested code): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function RunFormsLoop(parameter: pointer): PtrInt;begin  Forms.Application.Run;end; function RunFPHTTPAppLoop(parameter: pointer): PtrInt;begin  FPHTTPApp.Application.Run;end; function FormsLoopTerminated: Boolean;begin  Result := Forms.Application.Terminated;end; function FPHTTPAppLoopTerminated: Boolean;begin  Result := FPHTTPApp.Application.Terminated;end; ... begin  BeginThread(@RunFormsLoop);  BeginThread(@RunFPHTTPAppLoop);  repeat until FormsLoopTerminated and FPHTTPAppLoopTerminated;end.