You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-11-23 21:34:53 +02:00
Show more post information in the SimpleServer demo
Launch the default web browser from the SimpleServer demo.
This commit is contained in:
@@ -78,21 +78,31 @@ object SimpleServerFrm: TSimpleServerFrm
|
||||
Left = 312
|
||||
Top = 8
|
||||
Width = 105
|
||||
Height = 79
|
||||
Height = 21
|
||||
Caption = 'Start'
|
||||
TabOrder = 3
|
||||
OnClick = StartBtnClick
|
||||
end
|
||||
object StopBtn: TButton
|
||||
Left = 434
|
||||
Top = 8
|
||||
Left = 312
|
||||
Top = 37
|
||||
Width = 105
|
||||
Height = 79
|
||||
Height = 21
|
||||
Caption = 'Stop'
|
||||
Enabled = False
|
||||
TabOrder = 4
|
||||
OnClick = StopBtnClick
|
||||
end
|
||||
object OpenBtn: TButton
|
||||
Left = 312
|
||||
Top = 65
|
||||
Width = 105
|
||||
Height = 21
|
||||
Caption = 'Open web browser'
|
||||
Enabled = False
|
||||
TabOrder = 5
|
||||
OnClick = OpenBtnClick
|
||||
end
|
||||
end
|
||||
object ConnectionLogMem: TMemo
|
||||
Left = 0
|
||||
|
||||
@@ -8,9 +8,11 @@ uses
|
||||
{$IFDEF DELPHI16_UP}
|
||||
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
||||
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Samples.Spin, Vcl.ExtCtrls, System.Math,
|
||||
Winapi.ShellAPI,
|
||||
{$ELSE}
|
||||
Windows, Messages, SysUtils, Variants, Classes, Graphics,
|
||||
Controls, Forms, Dialogs, StdCtrls, Spin, ExtCtrls, Math,
|
||||
ShellAPI,
|
||||
{$ENDIF}
|
||||
uCEFInterfaces, uCEFServerComponent, uCEFTypes, uCEFMiscFunctions;
|
||||
|
||||
@@ -27,9 +29,11 @@ type
|
||||
BacklogEdt: TSpinEdit;
|
||||
StartBtn: TButton;
|
||||
StopBtn: TButton;
|
||||
OpenBtn: TButton;
|
||||
|
||||
procedure StartBtnClick(Sender: TObject);
|
||||
procedure StopBtnClick(Sender: TObject);
|
||||
procedure OpenBtnClick(Sender: TObject);
|
||||
procedure AddressEdtChange(Sender: TObject);
|
||||
|
||||
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
||||
@@ -161,30 +165,34 @@ begin
|
||||
try
|
||||
if (aPostData <> nil) and (aPostData.GetElementCount > 0) then
|
||||
begin
|
||||
ConnectionLogMem.Lines.Add('Post element count : ' + inttostr(aPostData.GetElementCount));
|
||||
aPostData.GetElements(aPostData.GetElementCount, TempArray);
|
||||
|
||||
i := 0;
|
||||
while (i < length(TempArray)) do
|
||||
begin
|
||||
if (TempArray[i].GetBytesCount > 0) then
|
||||
begin
|
||||
SetLength(TempBytes, TempArray[i].GetBytesCount);
|
||||
TempLen := TempArray[i].GetBytes(TempArray[i].GetBytesCount, @TempBytes[0]);
|
||||
case TempArray[i].GetType of
|
||||
PDE_TYPE_EMPTY : ConnectionLogMem.Lines.Add('Post element ' + inttostr(i) + ' type : empty');
|
||||
PDE_TYPE_FILE : ConnectionLogMem.Lines.Add('Post element ' + inttostr(i) + ' type : file. ' + TempArray[i].GetFile);
|
||||
PDE_TYPE_BYTES :
|
||||
begin
|
||||
ConnectionLogMem.Lines.Add('Post element ' + inttostr(i) + ' type : bytes');
|
||||
if (TempArray[i].GetBytesCount > 0) then
|
||||
begin
|
||||
SetLength(TempBytes, TempArray[i].GetBytesCount);
|
||||
TempLen := TempArray[i].GetBytes(TempArray[i].GetBytesCount, @TempBytes[0]);
|
||||
|
||||
if (TempLen > 0) then
|
||||
begin
|
||||
ConnectionLogMem.Lines.Add('Post contents length : ' + inttostr(TempLen));
|
||||
ConnectionLogMem.Lines.Add('Post contents sample : ' + BufferToString(TempBytes));
|
||||
end;
|
||||
end;
|
||||
if (TempLen > 0) then
|
||||
begin
|
||||
ConnectionLogMem.Lines.Add('Post element ' + inttostr(i) + ' length : ' + inttostr(TempLen));
|
||||
ConnectionLogMem.Lines.Add('Post element ' + inttostr(i) + ' contents : ' + BufferToString(TempBytes));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
inc(i);
|
||||
end;
|
||||
|
||||
i := 0;
|
||||
while (i < length(TempArray)) do
|
||||
begin
|
||||
TempArray[i] := nil;
|
||||
else
|
||||
ConnectionLogMem.Lines.Add('Post element ' + inttostr(i) + ' type : unknown');
|
||||
end;
|
||||
inc(i);
|
||||
end;
|
||||
end;
|
||||
@@ -195,6 +203,12 @@ begin
|
||||
finally
|
||||
if (TempArray <> nil) then
|
||||
begin
|
||||
i := 0;
|
||||
while (i < length(TempArray)) do
|
||||
begin
|
||||
TempArray[i] := nil;
|
||||
inc(i);
|
||||
end;
|
||||
Finalize(TempArray);
|
||||
TempArray := nil;
|
||||
end;
|
||||
@@ -204,26 +218,49 @@ end;
|
||||
function TSimpleServerFrm.BufferToString(const aBuffer : TBytes) : string;
|
||||
var
|
||||
i, j : integer;
|
||||
TempStream : TStringStream;
|
||||
begin
|
||||
Result := '';
|
||||
|
||||
i := 0;
|
||||
j := min(length(aBuffer), 5);
|
||||
TempStream := TStringStream.Create(aBuffer);
|
||||
try
|
||||
Result := TempStream.DataString;
|
||||
finally
|
||||
TempStream.Free;
|
||||
end;
|
||||
|
||||
while (i < j) do
|
||||
if (length(Result) = 0) then
|
||||
begin
|
||||
Result := Result + IntToHex(aBuffer[i], 2);
|
||||
inc(i);
|
||||
i := 0;
|
||||
j := length(aBuffer);
|
||||
|
||||
while (i < j) do
|
||||
begin
|
||||
Result := Result + IntToHex(aBuffer[i], 2);
|
||||
inc(i);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSimpleServerFrm.OpenBtnClick(Sender: TObject);
|
||||
var
|
||||
TempURL : string;
|
||||
begin
|
||||
TempURL := 'http://' + AddressEdt.Text + ':' + inttostr(PortEdt.Value);
|
||||
ShellExecute(0, 'Open', PChar(TempURL), nil, nil, SW_SHOW);
|
||||
end;
|
||||
|
||||
procedure TSimpleServerFrm.CEFServerComponent1ServerCreated(Sender: TObject; const server: ICefServer);
|
||||
begin
|
||||
if CEFServerComponent1.Initialized then
|
||||
begin
|
||||
ConnectionLogMem.Lines.Add('Server created');
|
||||
StartBtn.Enabled := False;
|
||||
StopBtn.Enabled := True;
|
||||
StartBtn.Enabled := False;
|
||||
StopBtn.Enabled := not(StartBtn.Enabled);
|
||||
OpenBtn.Enabled := not(StartBtn.Enabled);
|
||||
AddressEdt.Enabled := StartBtn.Enabled;
|
||||
PortEdt.Enabled := StartBtn.Enabled;
|
||||
BacklogEdt.Enabled := StartBtn.Enabled;
|
||||
end
|
||||
else
|
||||
ConnectionLogMem.Lines.Add('Server creation error!');
|
||||
@@ -236,8 +273,12 @@ begin
|
||||
else
|
||||
begin
|
||||
ConnectionLogMem.Lines.Add('Server destroyed');
|
||||
StartBtn.Enabled := True;
|
||||
StopBtn.Enabled := False;
|
||||
StartBtn.Enabled := True;
|
||||
StopBtn.Enabled := not(StartBtn.Enabled);
|
||||
OpenBtn.Enabled := not(StartBtn.Enabled);
|
||||
AddressEdt.Enabled := StartBtn.Enabled;
|
||||
PortEdt.Enabled := StartBtn.Enabled;
|
||||
BacklogEdt.Enabled := StartBtn.Enabled;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user