-
Notifications
You must be signed in to change notification settings - Fork 10
/
DW.DESIGN.MainForm.pas
259 lines (218 loc) · 7.54 KB
/
DW.DESIGN.MainForm.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
unit DW.DESIGN.MainForm;
interface
uses Classes, SysUtils, Windows, Vcl.Dialogs, DesignIntf, ToolsAPI, TypInfo;
type
TDWMainFormModuleCreator = class(TInterfacedObject, IOTACreator, IOTAModuleCreator)
private
FOwner: IOTAModule;
FHaveNames: Boolean;
FImplFileName: string;
FFormName: string;
public
constructor Create(AOwner: IOTAModule); overload;
// IOTACreator
function GetCreatorType: string;
function GetExisting: Boolean;
function GetFileSystem: string;
function GetOwner: IOTAModule;
function GetUnnamed: Boolean;
// IOTAModuleCreator
function GetAncestorName: string;
function GetImplFileName: string;
function GetIntfFileName: string;
function GetFormName: string;
function GetMainForm: Boolean;
function GetShowForm: Boolean;
function GetShowSource: Boolean;
function NewFormFile(const FormIdent, AncestorIdent: string): IOTAFile;
function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
function NewIntfSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
procedure FormCreated(const FormEditor: IOTAFormEditor);
end;
TDWmainFormModuleSource = class(TInterfacedObject, IOTAFile)
private
FModuleIdent: string;
FFormIdent: string;
FAncestorIdent: string;
public
constructor Create(const ModuleIdent, FormIdent, AncestorIdent: string);
// IOTAFile
function GetSource: string;
function GetAge: TDateTime;
end;
const
CrLf2 = #13#10#13#10;
CrLf = #13#10;
implementation
uses
System.Win.ComObj, DWForm, DW.CORE.Server;
procedure DebugMsg(const Msg: String);
begin
// ShowMessage(Msg);
end;
function GetActiveProjectGroup(const ModuleServices: IOTAModuleServices): IOTAProjectGroup;
var
I: Integer;
begin
Result := nil;
for I := 0 to ModuleServices.ModuleCount - 1 do
if Supports(ModuleServices.Modules[I], IOTAProjectGroup, Result) then
Break;
end;
constructor TDWMainFormModuleCreator.Create(AOwner: IOTAModule);
begin
inherited Create;
FOwner := AOwner;
end;
procedure TDWMainFormModuleCreator.FormCreated(const FormEditor: IOTAFormEditor);
var
aServer: IOTAComponent;
Form: IOTAComponent;
Method: TMethod;
PropInfo: PPropInfo;
TypeInfo: PTypeInfo;
NativeFormEditor: INTAFormEditor;
Server: TComponent;
begin
DebugMsg('FormCreated');
Form := FormEditor.GetRootComponent;
// Add OnShow Event
if Supports(FormEditor, INTAFormEditor, NativeFormEditor) then
begin
if NativeFormEditor.FormDesigner <> nil then
begin
TypeInfo := PTypeInfo(NativeFormEditor.FormDesigner.GetRoot.ClassInfo);
PropInfo := GetPropInfo(TypeInfo, 'OnShow');
// Method:= NativeFormEditor.FormDesigner.GetMethods('FormShow');
Method := NativeFormEditor.FormDesigner.CreateMethod('FormShow',
GetTypeData(PropInfo^.PropType^));
// if Assigned(Method) then
SetMethodProp(NativeFormEditor.FormDesigner.GetRoot, PropInfo, Method);
{ TODO 1 -oDELCIO -cIMPLEMENT : write OnShow Form Code }
// Write Method Code, see chapter 21 of PDF or 11 of online book:
// http://www.davidghoyle.co.uk/WordPress/wp-content/uploads/2016/03/The-Delphi-IDE-Open-Tools-API-Version-1.1.pdf
// other literature:
// http://www.delphipraxis.net/189813-sourcecode-fuer-zur-designtime-erzeugten-methode-per-designer-createmethod.html
// http://www.delphimaster.ru/cgi-bin/forum.pl?id=1234748058&n=12
// http://docwiki.embarcadero.com/Libraries/Seattle/en/System.Rtti.TRttiType.GetMethods
// http://stackoverflow.com/questions/27969212/how-to-find-index-of-a-method-in-an-interface*)
Server := NativeFormEditor.FormDesigner.CreateComponent(TDWServer,
NativeFormEditor.FormDesigner.GetRoot, 0, 0, 0, 0);
Server.Name := 'Server';
end;
end;
end;
function TDWMainFormModuleCreator.GetAncestorName: string;
begin
Result := 'Form';
end;
function TDWMainFormModuleCreator.GetCreatorType: string;
begin
Result := sForm;
end;
function TDWMainFormModuleCreator.GetExisting: Boolean;
begin
Result := False;
end;
function TDWMainFormModuleCreator.GetFileSystem: string;
begin
Result := '';
end;
function TDWMainFormModuleCreator.GetFormName: string;
begin
Result := 'FrmServerMain';
end;
function TDWMainFormModuleCreator.GetImplFileName: string;
begin
Result := GetCurrentDir + '\uServerMainForm.pas';
DebugMsg('GetImplFileName: ' + Result);
end;
function TDWMainFormModuleCreator.GetIntfFileName: string;
begin
Result := '';
end;
function TDWMainFormModuleCreator.GetMainForm: Boolean;
begin
Result := True;
DebugMsg('GetMainForm');
end;
function TDWMainFormModuleCreator.GetOwner: IOTAModule;
begin
if FOwner <> nil then
Result := FOwner
else
Result := GetActiveProject;
end;
function TDWMainFormModuleCreator.GetShowForm: Boolean;
begin
Result := True;
DebugMsg('GetShowForm');
end;
function TDWMainFormModuleCreator.GetShowSource: Boolean;
begin
Result := True;
DebugMsg('GetShowSource');
end;
function TDWMainFormModuleCreator.GetUnnamed: Boolean;
begin
Result := True;
DebugMsg('GetUnnamed');
end;
function TDWMainFormModuleCreator.NewFormFile(const FormIdent, AncestorIdent: string): IOTAFile;
begin
Result := nil;
DebugMsg('NewFormFile');
end;
function TDWMainFormModuleCreator.NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string)
: IOTAFile;
begin
Result := TDWmainFormModuleSource.Create(ModuleIdent, FormIdent, AncestorIdent);
DebugMsg('NewImplSource');
end;
function TDWMainFormModuleCreator.NewIntfSource(const ModuleIdent, FormIdent, AncestorIdent: string)
: IOTAFile;
begin
Result := nil;
DebugMsg('NewIntfSource');
end;
constructor TDWmainFormModuleSource.Create(Const ModuleIdent, FormIdent, AncestorIdent: string);
begin
inherited Create;
FModuleIdent := ModuleIdent;
FFormIdent := FormIdent; // Copy(FormIdent, 2, MaxInt);
FAncestorIdent := AncestorIdent; // Copy(AncestorIdent, 2,MaxInt);
DebugMsg('TDWFormModuleSource.Create: ' + FModuleIdent + ' ,' + FFormIdent + ' ,' +
FAncestorIdent);
end;
function TDWmainFormModuleSource.GetAge: TDateTime;
begin
Result := -1;
DebugMsg('GetAge: ' + DateToStr(Result));
end;
function TDWmainFormModuleSource.GetSource: string;
const
cSource = 'unit %0:s;' + CrLf2 +
'interface' + CrLf2 +
'uses' + CrLf + ' VCL.Forms, System.SysUtils, DW.CORE.Server;' + CrLf +
'type' + CrLf +
' T%1:s = class(T%2:s)' + CrLf + ' procedure FormShow(Sender: TObject);' + CrLf +
' private' + CrLf + '{ private declarations }' + CrLf + ' public' + CrLf +
' { public declarations }' + CrLf + ' end;' + CrLf2 +
'{ !!! Do Not Declare Global Variables !!! }' + CrLf2 +
'implementation' + CrLf + ' uses' + CrLf + ' uWebMainForm, uDWSessionData;' + CrLf2 +
'{$R *.dfm}' + CrLf2 +
'procedure T%1:s.FormShow(Sender: TObject);' + CrLf + 'begin' + CrLf +
' Server.MainForm:= TWebMainForm;' + CrLf +
// ' Server.UserDataModule:= TDWSessionData;' + CrLf +
' Server.DocDir := Server.AppPath + ''wwwroot\'';' + CrLf +
' Server.LibDir := Server.AppPath + ''wwwroot\dwlib\'';' + CrLf +
' Server.TemplateDir := Server.AppPath + ''wwwroot\templates\'';' + CrLf +
' ForceDirectories(Server.AppPath + ''wwwroot'');' + CrLf +
' ForceDirectories(Server.AppPath + ''wwwroot\templates'');' + CrLf + ' Server.Start;' + CrLf
+ 'end;' + CrLf +
'end.';
begin
Result := Format(cSource, [FModuleIdent, FFormIdent, FAncestorIdent]);
DebugMsg('GetSource: ' + Result);
end;
end.