| 1 |
unit FormUnit1; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses |
| 6 |
Winapi.Messages, System.SysUtils, System.Variants, |
| 7 |
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, |
| 8 |
Vcl.AppEvnts, Vcl.StdCtrls, IdHTTPWebBrokerBridge, Web.HTTPApp; |
| 9 |
|
| 10 |
type |
| 11 |
TForm1 = class(TForm) |
| 12 |
ButtonStart: TButton; |
| 13 |
ButtonStop: TButton; |
| 14 |
EditPort: TEdit; |
| 15 |
Label1: TLabel; |
| 16 |
ApplicationEvents1: TApplicationEvents; |
| 17 |
ButtonOpenBrowser: TButton; |
| 18 |
procedure FormCreate(Sender: TObject); |
| 19 |
procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); |
| 20 |
procedure ButtonStartClick(Sender: TObject); |
| 21 |
procedure ButtonStopClick(Sender: TObject); |
| 22 |
procedure ButtonOpenBrowserClick(Sender: TObject); |
| 23 |
private |
| 24 |
FServer: TIdHTTPWebBrokerBridge; |
| 25 |
procedure StartServer; |
| 26 |
{ private éž } |
| 27 |
public |
| 28 |
{ public éž } |
| 29 |
end; |
| 30 |
|
| 31 |
var |
| 32 |
Form1: TForm1; |
| 33 |
|
| 34 |
implementation |
| 35 |
|
| 36 |
{$R *.dfm} |
| 37 |
|
| 38 |
uses |
| 39 |
WinApi.Windows, Winapi.ShellApi; |
| 40 |
|
| 41 |
procedure TForm1.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); |
| 42 |
begin |
| 43 |
ButtonStart.Enabled := not FServer.Active; |
| 44 |
ButtonStop.Enabled := FServer.Active; |
| 45 |
EditPort.Enabled := not FServer.Active; |
| 46 |
end; |
| 47 |
|
| 48 |
procedure TForm1.ButtonOpenBrowserClick(Sender: TObject); |
| 49 |
var |
| 50 |
LURL: string; |
| 51 |
begin |
| 52 |
StartServer; |
| 53 |
LURL := Format('http://localhost:%s', [EditPort.Text]); |
| 54 |
ShellExecute(0, |
| 55 |
nil, |
| 56 |
PChar(LURL), nil, nil, SW_SHOWNOACTIVATE); |
| 57 |
end; |
| 58 |
|
| 59 |
procedure TForm1.ButtonStartClick(Sender: TObject); |
| 60 |
begin |
| 61 |
StartServer; |
| 62 |
end; |
| 63 |
|
| 64 |
procedure TForm1.ButtonStopClick(Sender: TObject); |
| 65 |
begin |
| 66 |
FServer.Active := False; |
| 67 |
FServer.Bindings.Clear; |
| 68 |
end; |
| 69 |
|
| 70 |
procedure TForm1.FormCreate(Sender: TObject); |
| 71 |
begin |
| 72 |
FServer := TIdHTTPWebBrokerBridge.Create(Self); |
| 73 |
end; |
| 74 |
|
| 75 |
procedure TForm1.StartServer; |
| 76 |
begin |
| 77 |
if not FServer.Active then |
| 78 |
begin |
| 79 |
FServer.Bindings.Clear; |
| 80 |
FServer.DefaultPort := StrToInt(EditPort.Text); |
| 81 |
FServer.Active := True; |
| 82 |
end; |
| 83 |
end; |
| 84 |
|
| 85 |
end. |