-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDWUrlHandlerForms.pas
94 lines (78 loc) · 2.67 KB
/
DWUrlHandlerForms.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
unit DWUrlHandlerForms;
interface
uses
{$IFDEF MSWINDOWS}
Windows,
{$ENDIF}
Classes, SysUtils,
System.StrUtils,
OverbyteIcsHttpSrv,
OverbyteIcsHttpAppServer,
DWUrlHandlerBase, DWUtils;
type
TUrlHandlerForms = class(TDWUrlHandlerBase)
public
procedure Execute; override;
end;
implementation
uses DW.CORE.Server, DWForm, DW.CORE.DWClientConnection, DW.CORE.DWApplication;
procedure TUrlHandlerForms.Execute;
var
LDWApplication: TDWApplication;
GetUrl: string;
I: Integer;
LForm, auxForm: TDWForm;
Location: string;
Status: string;
begin
Status := '';
GetUrl := (Client as TDWClientConnection).Path;
LDWApplication := DWApplication;
if LDWApplication = nil then
Exit;
{ TODO 1 -oDELCIO -cIMPLEMENT : Change to render DWApplication.Active Form (by DWForm.Show) }
if LDWApplication.MainForm = nil then // if MainForm not exists
begin // Create and redirect to it
LDWApplication.MainForm := LDWApplication.MainFormClass.Create(DWApplication);
LDWApplication.MainForm.Show; // LDWApplication.ActiveForm:= LDWApplication.MainForm;
// LDWApplication.AddForm(LDWApplication.MainForm);
TDWClientConnection(Client).DocStream := LDWApplication.MainForm.Render;
Location := '/' + LDWApplication.MainForm.Name;
end
else
begin
// check if url represent one created form
LForm := nil;
for I := 0 to LDWApplication.Forms.Count - 1 do
begin
auxForm := TDWForm(LDWApplication.Forms[I]);
if AnsiEndsText(auxForm.Name, GetUrl) then
begin
LForm := auxForm;
Break;
end;
end;
if LForm <> nil then // if form found
begin
LForm.Show; // LDWApplication.ActiveForm:= LForm;
TDWClientConnection(Client).DocStream := LForm.Render; // render form
Location := '/' + LForm.Name;
end
else
begin
LDWApplication.MainForm.Show; // LDWApplication.ActiveForm:= LDWApplication.MainForm;
TDWClientConnection(Client).DocStream := LDWApplication.MainForm.Render;
// render main form
Location := '/' + LDWApplication.MainForm.Name;
end;
end;
if Location <> GetUrl then
begin
Status := '302 moved';
TDWClientConnection(Client).ReplyHeader := TDWClientConnection(Client).ReplyHeader +
'Location: ' + Location;
end;
AnswerStream(Status, '', TDWClientConnection(Client).ReplyHeader);
Finish;
end;
end.