-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathResources.pas
1832 lines (1734 loc) · 58 KB
/
Resources.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Unit Resources;
Interface
Uses Windows,Messages, SysUtils, Classes, ComCtrls, AppEvnts, UfrmFormTree,
Controls, StdCtrls, Graphics, Forms, Menus,ExtCtrls,Def_res,ActnList,
StdActns,ExtActns,Buttons,Mask,Grids,CheckLst,Chart,Series,MPlayer,
Tabs,Outline,TabNotBk,FileCtrl,Spin,ColorGrd,Gauges,DirOutln,Calendar,ValEdit;
Type
IdrDfmLoader=class;
//Records to resource list
TDfm = class
Open:Byte; //2 - form opened; 1 - form closed but loader not destroyed; 0 - form closed
Flags:Byte; //Form flags (see FF_...)
ResName:AnsiString; //Resource name (ABOUTDIALOG)
Name:AnsiString; //Form name (AboutDialog)
FormClass:AnsiString; //Form class (TAboutDialog)
MemStream:TMemoryStream; //Memory Stream, containing Resource Data
ParentDfm:TDfm; //Parent form
Events:TList; //Form events list
Components:TList; //Form components list
Form:TForm; //Pointer to opened form
Loader:IdrDfmLoader; //Form loader
Function IsFormComponent(CompName:AnsiString):Boolean;
Constructor Create;
Destructor Destroy; Override;
end;
TResourceInfo = class
citadel:Boolean;
Counter:Integer;
hFormPlugin:HINST;
FormPluginName:AnsiString;
FormList:TList; //Form names list
Aliases:TStringList; //Aliases list
Constructor Create;
Destructor Destroy; Override;
Procedure GetFormAsText(Dfm:TDfm; DstList:TStrings);
Function EnumResources(FileName:AnsiString):Boolean;
Procedure ShowResources(ListBox:TListBox);
Procedure GetBitmap(Dfm:TDfm; DstBitmap:TBitmap);
Function GetParentDfm(Dfm:TDfm):TDfm;
Procedure CloseAllForms;
Procedure ReopenAllForms;
Procedure InitAliases;
Function GetAlias(ClasName:AnsiString):AnsiString;
Function GetFormIdx(FormName:AnsiString; var idx:Integer):TDfm;
Function GetFormByClassName(ClasName:AnsiString):TDfm;
Procedure GetEventsList(FormName:AnsiString; Lst:TList);
end;
TMyControl = class(TControl)
Published
property OnClick;
property OnMouseDown;
property PopupMenu;
end;
IdrDfmReader = class(TReader)
Published
property PropName;
end;
TComponentEvents = class(TCollectionItem)
Component:TComponent;
FoundEvents:TStringList;
Constructor Create(Owner:TCollection); Override;
Destructor Destroy; Override;
end;
IdrDfmForm = class(TForm)
private
FOnFindMethod:TFindMethodSourceEvent;
Function getFormName:AnsiString;
Procedure DoFindMethod(methodName:AnsiString);
Procedure CMDialogKey(var Message:TCMDialogKey); Message CM_DIALOGKEY;
Procedure MyFormShow(Sender:TObject);
Procedure MyFormClose(Sender:TObject; var Action:TCloseAction);
Procedure MyFormKeyDown(Sender:TObject; var Key:Word; Shift:TShiftState);
Procedure MyShortCutEvent(var Msg:TWMKey; Var Handled:Boolean);
Procedure ShowMyPopupMenu(FormName, ControlName:AnsiString; show:Boolean);
protected
Procedure CreateHandle; Override;
Procedure SetupControlHint(FormName:AnsiString; Control:TControl; InitHint:AnsiString);
Procedure SetupMenuItem(mi:TMenuItem; searchName:AnsiString);
Procedure ActionExecute(Sender:TObject);
Procedure miClick(Sender:TObject);
Procedure ControlMouseDown(Sender:TObject; Button:TMouseButton; Shift:TShiftState; X, Y:Integer);
Procedure miPopupClick(Sender:TObject);
public
originalClassName:AnsiString;
originalClassType:AnsiString;
current:TComponentEvents;
compsEventsList:TCollection;
evPopup:TPopupMenu;
frmTree:TIdrDfmFormTree;
Procedure SetupControls;
Procedure SetupControlResetShortcut(component:TComponent);
Procedure SetDesigning(value, SetChildren:Boolean);
Procedure SetMyHandlers;
constructor Create(AOwner:TComponent); overload; override;
constructor Create2(AOwner:TComponent; Dummy:Integer);
Destructor Destroy; Override;
property OnFindMethod:TFindMethodSourceEvent read FOnFindMethod write FOnFindMethod;
end;
IdrDfmLoader = class(TComponent)
private
dfmForm:IdrDfmForm;
FOnFindMethod:TFindMethodSourceEvent;
protected
Counter:Integer;
Current:TComponentEvents;
CompsEventsList:TCollection;
lastClassAliasName:AnsiString;
procedure AncestorNotFound(Reader:TReader; Const ComponentName:AnsiString; ComponentClass:TPersistentClass; var Component:TComponent);
procedure ReaderError(Reader:TReader; const Message:AnsiString; Var Handled:Boolean);
procedure FindComponentClass(Reader:TReader; Const ClasName:AnsiString; var ComponentClass:TComponentClass);
procedure CreateComponent(Reader:TReader; ComponentClass:TComponentClass; var Component:TComponent);
procedure FindMethod(Reader:TReader; Const MethodName:AnsiString; var Address:Pointer; Var Error:Boolean);
procedure SetComponentName(Reader:TReader; Component:TComponent; Var Name:AnsiString);
procedure DoReferenceName(Reader:TReader; Var Name:AnsiString);
Function HasGlyph(ClasName:AnsiString):Boolean;
public
Constructor Create(Owner:TComponent); Override;
Destructor Destroy; Override;
Function LoadForm(dfmStream:TStream; Dfm:TDfm; loadingParent:Boolean = false):TForm;
property OnFindMethod:TFindMethodSourceEvent read FOnFindMethod write FOnFindMethod;
end;
IdrDfmDefaultControl = class(TPanel)
private
originalClassName, mappedClassName:AnsiString;
//image for std nonvisual controls (dialogs, etc) (dclstd60.bpl has images)
imgIcon:TImage;
Procedure ImageMouseDown(Sender:TObject; Button:TMouseButton; Shift:TShiftState; X, Y:Integer);
Function HasIconForClass(const name:AnsiString):Boolean;
Procedure CreateImageIconForClass(const imgFile:AnsiString);
protected
Procedure Loaded; Override;
Procedure ReadState(Reader:TReader); Override;
Procedure Paint; Override;
public
Constructor Create(Owner:TComponent); Override;
Function IsVisible:Boolean;
Procedure SetClassName(const name, mappedName:AnsiString);
Property OrigClassName:AnsiString Read originalClassName;
end;
{IdrImageControl = class(TImage)
protected
Procedure Paint; Override;
public
Constructor Create(Owner:TComponent); Override;
end;}
Const
RegClasses:Array[0..115] of RegClassInfo = (
//Standard
(RegClass:TFrame; ClasName: 'TFrame'),
(RegClass:TMainMenu; ClasName: 'TMainMenu'),
(RegClass:TPopupMenu; ClasName: 'TPopupMenu'),
(RegClass:TLabel; ClasName: 'TLabel'),
(RegClass:TEdit; clasName: 'TEdit'),
(RegClass:TLabeledEdit; clasName: 'TLabeledEdit'),
(RegClass:TMemo; clasName: 'TMemo'),
(RegClass:TButton; clasName: 'TButton'),
(RegClass:TCheckBox; clasName: 'TCheckBox'),
(RegClass:TRadioButton; clasName: 'TRadioButton'),
(RegClass:TListBox; clasName: 'TListBox'),
(RegClass:TComboBox; clasName: 'TComboBox'),
(RegClass:TScrollBar; clasName: 'TScrollBar'),
(RegClass:TGroupBox; clasName: 'TGroupBox'),
(RegClass:TRadioGroup; clasName: 'TRadioGroup'),
(RegClass:TPanel; clasName: 'TPanel'),
(RegClass:TActionList; clasName: 'TActionList'),
(RegClass:TAction; clasName: 'TAction'),
(RegClass:TEditCut; clasName: 'TEditCut'),
(RegClass:TEditCopy; clasName: 'TEditCopy'),
(RegClass:TEditPaste; clasName: 'TEditPaste'),
(RegClass:TEditSelectAll; clasName: 'TEditSelectAll'),
(RegClass:TEditUndo; clasName: 'TEditUndo'),
(RegClass:TEditDelete; clasName: 'TEditDelete'),
(RegClass:TWindowClose; clasName: 'TWindowClose'),
(RegClass:TWindowCascade; clasName: 'TWindowCascade'),
(RegClass:TWindowTileHorizontal; clasName: 'TWindowTileHorizontal'),
(RegClass:TWindowTileVertical; clasName: 'TWindowTileVertical'),
(RegClass:TWindowMinimizeAll; clasName: 'TWindowMinimizeAll'),
(RegClass:TWindowArrange; clasName: 'TWindowArrange'),
(RegClass:THelpContents; clasName: 'THelpContents'),
(RegClass:THelpTopicSearch; clasName: 'THelpTopicSearch'),
(RegClass:THelpOnHelp; clasName: 'THelpOnHelp'),
(RegClass:THelpContextAction; clasName: 'THelpContextAction'),
(RegClass:TFileOpen; clasName: 'TFileOpen'),
(RegClass:TFileOpenWith; clasName: 'TFileOpenWith'),
(RegClass:TFileSaveAs; clasName: 'TFileSaveAs'),
(RegClass:TFilePrintSetup; clasName: 'TFilePrintSetup'),
(RegClass:TFileExit; clasName: 'TFileExit'),
(RegClass:TSearchFind; clasName: 'TSearchFind'),
(RegClass:TSearchReplace; clasName: 'TSearchReplace'),
(RegClass:TSearchFindFirst; clasName: 'TSearchFindFirst'),
(RegClass:TSearchFindNext; clasName: 'TSearchFindNext'),
(RegClass:TFontEdit; clasName: 'TFontEdit'),
(RegClass:TColorSelect; clasName: 'TColorSelect'),
(RegClass:TPrintDlg; clasName: 'TPrintDlg'),
//TRichEditxxx actions?
//TListControlXXX ?
(RegClass:TOpenPicture; clasName: 'TOpenPicture'),
(RegClass:TSavePicture; clasName: 'TSavePicture'),
//Additional
(RegClass:TBitBtn; clasName: 'TBitBtn'),
(RegClass:TSpeedButton; clasName: 'TSpeedButton'),
(RegClass:TMaskEdit; clasName: 'TMaskEdit'),
(RegClass:TStringGrid; clasName: 'TStringGrid'),
(RegClass:TDrawGrid; clasName: 'TDrawGrid'),
(RegClass:TImage; clasName: 'TImage'),
(RegClass:TPicture; clasName: 'TPicture'),
(RegClass:TBitmap; clasName: 'TBitmap'),
(RegClass:TGraphic; clasName: 'TGraphic'),
(RegClass:TMetafile; clasName: 'TMetafile'),
(RegClass:TIcon; clasName: 'TIcon'),
(RegClass:TShape; clasName: 'TShape'),
(RegClass:TBevel; clasName: 'TBevel'),
(RegClass:TScrollBox; clasName: 'TScrollBox'),
(RegClass:TCheckListBox; clasName: 'TCheckListBox'),
(RegClass:TSplitter; clasName: 'TSplitter'),
(RegClass:TStaticText; clasName: 'TStaticText'),
(RegClass:TControlBar; clasName: 'TControlBar'),
(RegClass:TChart; clasName: 'TChart'),
(RegClass:TBarSeries; clasName: 'TBarSeries'),
(RegClass:THorizBarSeries; clasName: 'THorizBarSeries'),
(RegClass:TPointSeries; clasName: 'TPointSeries'),
(RegClass:TAreaSeries; clasName: 'TAreaSeries'),
(RegClass:TLineSeries; clasName: 'TLineSeries'),
(RegClass:TFastLineSeries; clasName: 'TFastLineSeries'),
(RegClass:TPieSeries; clasName: 'TPieSeries'),
(RegClass:TColorBox; clasName: 'TColorBox'),
//Win32
(RegClass:TTabControl; clasName: 'TTabControl'),
(RegClass:TPageControl; clasName: 'TPageControl'),
(RegClass:TTabSheet; clasName: 'TTabSheet'),
(RegClass:TImageList; clasName: 'TImageList'),
(RegClass:TRichEdit; clasName: 'TRichEdit'),
(RegClass:TTrackBar; clasName: 'TTrackBar'),
(RegClass:TProgressBar; clasName: 'TProgressBar'),
(RegClass:TUpDown; clasName: 'TUpDown'),
(RegClass:THotKey; clasName: 'THotKey'),
(RegClass:TAnimate; clasName: 'TAnimate'),
(RegClass:TDateTimePicker; clasName: 'TDateTimePicker'),
(RegClass:TMonthCalendar; clasName: 'TMonthCalendar'),
(RegClass:TTreeView; clasName: 'TTreeView'),
(RegClass:TListView; clasName: 'TListView'),
(RegClass:THeaderControl; clasName: 'THeaderControl'),
(RegClass:TStatusBar; clasName: 'TStatusBar'),
(RegClass:TToolBar; clasName: 'TToolBar'),
(RegClass:TToolButton; clasName: 'TToolButton'),
(RegClass:TCoolBar; clasName: 'TCoolBar'),
(RegClass:TComboBoxEx; clasName: 'TComboBoxEx'),
(RegClass:TPageScroller; clasName: 'TPageScroller'),
//System
//RegClass:TPaintBox),
(RegClass:TMediaPlayer; clasName: 'TMediaPlayer'),
//Win 3.1
(RegClass:TTabSet; clasName: 'TTabSet'),
(RegClass:TOutline; clasName: 'TOutline'),
(RegClass:TTabbedNotebook; clasName: 'TTabbedNotebook'),
(RegClass:TNotebook; clasName: 'TNotebook'),
(RegClass:TPage; clasName: 'TPage'),
(RegClass:THeader; clasName: 'THeader'),
(RegClass:TFileListBox; clasName: 'TFileListBox'),
(RegClass:TDirectoryListBox; clasName: 'TDirectoryListBox'),
(RegClass:TDriveComboBox; clasName: 'TDriveComboBox'),
(RegClass:TFilterComboBox; clasName: 'TFilterComboBox'),
//Samples
//(RegClass:TPerformanceGraph; clasName: 'TPerformanceGraph'),
(RegClass:TSpinButton; clasName: 'TSpinButton'),
(RegClass:TTimerSpeedButton; clasName: 'TTimerSpeedButton'),
(RegClass:TSpinEdit; clasName: 'TSpinEdit'),
(RegClass:TColorGrid; clasName: 'TColorGrid'),
(RegClass:TGauge; clasName: 'TGauge'),
(RegClass:TDirectoryOutline; clasName: 'TDirectoryOutline'),
(RegClass:TCalendar; clasName: 'TCalendar'),
//(RegClass:TPie; clasName: 'TPie'),
(RegClass:TValueListEditor; clasName: 'TValueListEditor'),
(RegClass:IdrDfmDefaultControl; clasName: 'Default')
//(RegClass:Nil; clasName:'')
);
Implementation
Uses
Misc,Main,Dialogs,StrUtils,Infos,Def_info,Def_main;
Type
PfnGetDstSize = Function (MemPtr:Pointer; Len:Integer):Integer; stdcall;
PfnDecrypt = Function (SrcPtr:Pointer; SrcLen:Integer; DstPtr:Pointer; DstLen:Integer):Boolean; stdcall;
Var
classesRegistered:Boolean;
fnGetDstSize:PfnGetDstSize;
fnDecrypt:PfnDecrypt;
Constructor TDfm.Create;
Begin
MemStream:=TMemoryStream.Create;
Events:=TList.Create;
Components:=TList.Create;
end;
Destructor TDfm.Destroy;
Var
n,m:Integer;
cInfo:PComponentInfo;
Begin
MemStream.Free;
for n := 0 to Events.Count-1 do
Finalize(PEventInfo(Events[n])^);
Events.Free;
for n := 0to Components.Count-1 do
begin
cInfo := Components[n];
if Assigned(cInfo.Events) then
begin
for m := 0 to cInfo.Events.Count-1 do
Finalize(PEventInfo(cInfo.Events[m])^);
cInfo.Events.Free;
end;
Finalize(cInfo^);
end;
Components.Free;
Form.Free;
Loader.Free;
Inherited;
end;
Function TDfm.IsFormComponent (CompName:AnsiString):Boolean;
var
m:Integer;
Begin
Result:=False;
For m:=0 to Components.Count-1 do
if SameText(CompName, PComponentInfo(Components[m]).Name) then
Begin
Result:=true;
Exit;
end;
end;
Constructor TResourceInfo.Create;
var
n:Integer;
Begin
FormList:=TList.Create;
Aliases:=TStringList.Create;
if not ClassesRegistered then
Begin
for n := Low(RegClasses) to High(RegClasses) do
RegisterClass(RegClasses[n].RegClass);
ClassesRegistered := true;
end;
end;
Destructor TResourceInfo.Destroy;
Var
n:Integer;
Begin
if hFormPlugin<>0 then
begin
FreeLibrary(hFormPlugin);
hFormPlugin := 0;
end;
for n := 0 to FormList.Count-1 do
TDfm(FormList[n]).Free;
FormList.Free;
Aliases.Free;
Inherited;
end;
Function AnalyzeSection(Dfm:TDfm;FormText:TStringList; From:Integer; cInfo:PComponentInfo; objAlign:Integer):Integer;
var
n, _pos, _end,tmp,off,align:Integer;
componentName, componentClass, eventName, procName,line:AnsiString;
_Info:PComponentInfo;
eInfo:PEventInfo;
is_inherit:Boolean;
Begin
n := From;
While n < FormText.Count do
begin
line := Trim(FormText[n]);
if line = '' then
begin
Inc(n);
continue;
end;
align := Pos(line,FormText[n]);
if SameText(line, 'end') and (align = objAlign) then break;
is_inherit := Pos('inherited ',line) = 1;
if (Pos('object ',line) = 1) or is_inherit then
begin
_pos := Pos(':',line);
_end := Length(line);
tmp := Pos(' [',line); //eg: object Label1: TLabel [1]
if tmp<>0 then _end := tmp - 1;
if is_inherit then off:=10 else off:=7;
//object Label1: TLabel
if _pos<>0 then
begin
componentName := Trim(Copy(line,off, _pos - off));
componentClass := Trim(Copy(line,_pos + 1, _end - _pos));
End
//object TLabel
else
begin
componentName := '_' + Val2Str(ResInfo.Counter,4) + '_';
Inc(ResInfo.Counter);
componentClass := Trim(Copy(line,off, _end - off + 1));
End;
New(_Info);
with _Info^ do
begin
inherit := is_inherit;
HasGlyph := false;
Name := componentName;
ClasName := componentClass;
Events := TList.create;
end;
Dfm.Components.Add(_Info);
if ResInfo.Aliases.IndexOf(_Info.ClasName) = -1 then
ResInfo.Aliases.Add(_Info.ClasName);
n := AnalyzeSection(Dfm, FormText, n + 1, _Info, align);
End;
//Events begins with "On" or "Action". But events of TDataSet may begin with no these prefixes!!!
_pos := Pos('=',line);
if _pos <> 0 Then
if ((line[1] = 'O') and (line[2] = 'n')) or (Pos('Action ',line) = 1) then
begin
eventName := Trim(Copy(line,1, _pos - 1)); //Include "On"
procName := Trim(Copy(line,_pos + 1, Length(line) - _pos));
New(eInfo);
eInfo.EventName := eventName;
eInfo.ProcName := procName;
//Form itself
if CInfo=Nil then Dfm.Events.Add(eInfo)
else CInfo.Events.Add(eInfo);
End;
//Has property Glyph?
if Pos('Glyph.Data =',line) = 1 Then CInfo.HasGlyph := true;
Inc(n);
End;
Result:=n;
end;
Function EnumResNameProcedure(hModule:Integer; _Type, Name:PAnsiChar; Param:TResourceInfo):BOOL; stdcall;
var
res,is_inherit:Boolean;
srcSize, dstSize:Integer;
dfm:TDfm;
formText:TStringList;
ms,ds:TMemoryStream;
resStream:TResourceStream;
mp:PAnsiChar;
line:AnsiString;
off,_pos:Integer;
signature:Array[1..4] of Char;
len:Byte;
Begin
if (_Type = RT_RCDATA) or (_Type = RT_BITMAP) then
begin
resStream := TResourceStream.Create(hModule, Name, _Type);
if _Type = RT_RCDATA then
begin
ms := TMemoryStream.Create;
ms.LoadFromStream(resStream);
res := true;
if ResInfo.hFormPlugin<>0 then
begin
@fnGetDstSize := GetProcAddress(ResInfo.hFormPlugin, 'GetDstSize');
@fnDecrypt := GetProcAddress(ResInfo.hFormPlugin, 'Decrypt');
res := Assigned(fnGetDstSize) and Assigned(fnDecrypt);
if res then
begin
srcSize := ms.Size;
dstSize := fnGetDstSize(ms.Memory, srcSize);
if srcSize <> dstSize then
begin
ds := TMemoryStream.Create;
ds.Size := dstSize;
res := fnDecrypt(ms.Memory, srcSize, ds.Memory, dstSize);
ms.Size := dstSize;
ms.CopyFrom(ds, dstSize);
ds.free;
end
else res := fnDecrypt(ms.Memory, srcSize, ms.Memory, dstSize);
end;
if res then
begin
mp := ms.Memory;
len := Byte((mp + 4)^);
res := (len = strlen(Name)) and SameText(Name, MakeString(mp + 5, len));
End;
end;
if res then
begin
ms.Seek(0, soFromBeginning);
ms.Read(signature, 4);
if (signature[1] = 'T') And (signature[2] = 'P') and (signature[3] = 'F')
and (signature[4] in ['0'..'7']) then
begin
if signature[4] = '0' then
begin
//Äîáàâëÿåì â ñïèñîê ðåñóðñîâ
dfm := TDfm.Create;
dfm.ResName := Name;
dfm.MemStream := ms;
//Analyze text representation
formText := TStringList.Create;
ResInfo.GetFormAsText(dfm, formText);
line := formText[0];
is_inherit := Pos('inherited ',line) = 1;
if is_inherit then dfm.Flags:=dfm.flags or FF_INHERITED;
if (Pos('object ',line) = 1) or is_inherit then
begin
if is_inherit Then off := 10 else off:=7;
_pos := Pos(':',line);
dfm.Name := Trim(Copy(line,off, _pos - off));
dfm.FormClass := Trim(Copy(line,_pos + 1, Length(line) - _pos));
AnalyzeSection(dfm, formText, 1, Nil, 1);
end;
formText.free;
Param.FormList.Add(dfm);
end
else if not ResInfo.citadel then
begin
ShowMessage('Citadel for Delphi detected, forms cannot be loaded');
ResInfo.citadel := true;
End;
end
else ms.Free;
end
else ms.free;
end
else if _Type = RT_BITMAP then
begin
dfm := TDfm.Create;
dfm.ResName := Name;
dfm.MemStream.LoadFromStream(resStream);
Param.FormList.Add(dfm);
end;
resStream.free;
End;
Result:=true;
end;
Function TResourceInfo.EnumResources (FileName:AnsiString):Boolean;
var
_Inst:HINST;
Begin
Result:=false;
hFormPlugin := LoadLibrary(PAnsiChar(FMain.AppDir + 'Plugins\' + FormPluginName));
_Inst := LoadLibraryEx(PAnsiChar(FileName), 0, LOAD_LIBRARY_AS_DATAFILE);
if _Inst<>0 then
begin
EnumResourceNames(_Inst, RT_RCDATA, @EnumResNameProcedure, Integer(Self));
FreeLibrary(_Inst);
Result:=true;
Exit;
end;
if hFormPlugin<>0 then
begin
FreeLibrary(hFormPlugin);
hFormPlugin := 0;
end;
end;
Procedure TResourceInfo.ShowResources (ListBox:TListBox);
var
Wid,maxwid,n:Integer;
canva:TCanvas;
dfm:TDfm;
Begin
ListBox.Clear;
maxwid := 0;
canva := ListBox.Canvas;
for n := 0 to FormList.Count-1 do
begin
dfm := TDfm(FormList[n]);
ListBox.Items.Add(dfm.ResName + ' {' + dfm.Name + '}');
wid := canva.TextWidth(dfm.ResName);
if wid > maxwid then maxwid := wid;
end;
ListBox.ScrollWidth := maxwid + 2;
end;
Procedure TResourceInfo.GetFormAsText (Dfm:TDfm; DstList:TStrings);
var
ms:TMemoryStream;
Begin
ms:=TMemoryStream.Create;
try
ms.Size := Dfm.MemStream.Size;
Dfm.MemStream.Seek(0, soFromBeginning);
ObjectBinaryToText(Dfm.MemStream, ms);
ms.Seek(0, soFromBeginning);
DstList.LoadFromStream(ms);
Finally
ms.Free;
end;
end;
Procedure TResourceInfo.GetBitmap (Dfm:TDfm; DstBitmap:TBitmap);
Begin
Dfm.MemStream.Seek(0, soFromBeginning);
DstBitmap.LoadFromStream(Dfm.MemStream);
end;
Function TResourceInfo.GetParentDfm (Dfm:TDfm):TDfm;
var
parentName:AnsiString;
n:Integer;
Begin
parentName := GetParentName(Dfm.FormClass);
for n := 0 to FormList.Count-1 do
begin
Result:= TDfm(FormList[n]);
if SameText(Result.FormClass, parentName) then Exit;
end;
Result:=Nil;
end;
Procedure TResourceInfo.CloseAllForms;
var
n:Integer;
dfm:TDfm;
Begin
for n := 0 to FormList.Count-1 do
begin
dfm := TDfm(FormList[n]);
if dfm.Open = 2 then
begin
if Assigned(dfm.Form) and dfm.Form.Visible then dfm.Form.Close;
dfm.Form := Nil;
dfm.Open := 1;
End;
if dfm.Open = 1 then
begin
dfm.Loader.Free;
dfm.Form := Nil;
dfm.Loader := Nil;
dfm.Open := 0;
End;
end;
//this is a must have call!
//it removes just closed form from the Screen->Forms[] list!
//and we'll not have a new form with name [old_name]_1 !
Application.ProcessMessages;
end;
Procedure TResourceInfo.ReopenAllForms;
var
n,Idx:Integer;
dfm:TDfm;
FormName:AnsiString;
Begin
for n := 0 to FormList.Count-1 do
begin
dfm := TDfm(FormList[n]);
if dfm.Open = 2 Then //still opened
if Assigned(dfm.Form) and dfm.Form.Visible then
begin
FormName := dfm.Form.Name;
dfm.Form.Close;
//this is a must have call!
//it removes just closed form from the Screen->Forms[] list!
//and we'll not have a new form with name [old_name]_1 !
Application.ProcessMessages;
Idx := -1;
dfm := GetFormIdx(FormName, Idx);
FMain.ShowDfm(dfm);
End;
end;
end;
Procedure TResourceInfo.InitAliases;
var
n:Integer;
Alias,clasName:AnsiString;
componentClass:TPersistentClass;
Begin
for n := 0 to Aliases.Count-1 do
begin
clasName := Aliases[n];
if Pos('=',clasName)=0 then
begin
alias := '';
try
componentClass := FindClass(clasName);
except
on E:Exception do
begin
if SameText(clasName, 'TDBGrid') then alias := 'TStringGrid'
else if SameText(clasName, 'TDBText') Then alias := 'TLabel'
else if SameText(clasName, 'TDBEdit') Then alias := 'TEdit'
else if SameText(clasName, 'TDBMemo') then alias := 'TMemo'
else if SameText(clasName, 'TDBImage') Then alias := 'TImage'
else if SameText(clasName, 'TDBListBox') then alias := 'TListBox'
else if SameText(clasName, 'TDBComboBox') then alias := 'TComboBox'
else if SameText(clasName, 'TDBCheckBox') then alias := 'TCheckBox'
else if SameText(clasName, 'TDBRadioGroup') then alias := 'TRadioGroup'
else if SameText(clasName, 'TDBLookupListBox') then alias := 'TListBox'
else if SameText(clasName, 'TDBLookupComboBox') then alias := 'TComboBox'
else if SameText(clasName, 'TDBRichEdit') then alias := 'TRichEdit'
else if SameText(clasName, 'TDBCtrlGrid') then alias := 'TStringGrid'
else if SameText(clasName, 'TDBChart') then alias := 'TChart'
//sample components are redirected to TCxxx components
else if SameText(clasName, 'TGauge') then alias := 'TCGauge'
else if SameText(clasName, 'TSpinEdit') then alias := 'TSpinEdit'
else if SameText(clasName, 'TSpinButton') then alias := 'TSpinButton'
else if SameText(clasName, 'TCalendar') then alias := 'TCalendar'
else if SameText(clasName, 'TDirectoryOutline') then alias := 'TDirectoryOutline'
else if SameText(clasName, 'TShellImageList') then alias := 'TImageList'
//special case, if not handled - crash (eg:1st Autorun Express app)
else if GetClass(clasName)=Nil then
begin
if IsInheritsByclassName(clasName, 'TBasicAction') then alias := 'TAction'
else if IsInheritsByclassName(clasName, 'TMainMenu') then alias := 'TMainMenu'
else if IsInheritsByclassName(clasName, 'TPopupMenu') then alias := 'TPopupMenu'
else if IsInheritsByclassName(clasName, 'TCustomLabel') or
AnsiContainsText (clasName, 'Label') then alias:= 'TLabel' //evristika
else if IsInheritsByclassName(clasName, 'TCustomEdit') then alias := 'TEdit'
else if IsInheritsByclassName(clasName, 'TCustomMemo') then alias := 'TMemo'
else if IsInheritsByclassName(clasName, 'TButton') then alias := 'TButton'
else if IsInheritsByclassName(clasName, 'TCustomCheckBox') then alias := 'TCheckBox'
else if IsInheritsByclassName(clasName, 'TRadioButton') then alias := 'TRadioButton'
else if IsInheritsByclassName(clasName, 'TCustomListBox') then alias := 'TListBox'
else if IsInheritsByclassName(clasName, 'TCustomComboBox') then alias := 'TComboBox'
else if IsInheritsByclassName(clasName, 'TCustomGroupBox') then alias := 'TGroupBox'
else if IsInheritsByclassName(clasName, 'TCustomRadioGroup') then alias := 'TRadioGroup'
else if IsInheritsByclassName(clasName, 'TCustomPanel') then alias := 'TPanel'
else if IsInheritsByclassName(clasName, 'TBitBtn') then alias := 'TBitBtn'
else if IsInheritsByclassName(clasName, 'TSpeedButton') then alias := 'TSpeedButton'
else if IsInheritsByclassName(clasName, 'TImage') then alias := 'TImage'
else if IsInheritsByclassName(clasName, 'TImageList') then alias := 'TImageList'
else if IsInheritsByclassName(clasName, 'TBevel') then alias := 'TBevel'
else if IsInheritsByclassName(clasName, 'TSplitter') then alias := 'TSplitter'
else if IsInheritsByclassName(clasName, 'TPageControl') then alias := 'TPageControl'
else if IsInheritsByclassName(clasName, 'TToolBar') then alias := 'TToolBar'
else if IsInheritsByclassName(clasName, 'TToolButton') then alias := 'TToolButton'
else if IsInheritsByclassName(clasName, 'TCustomStatusBar') then alias := 'TStatusBar'
else if IsInheritsByclassName(clasName, 'TDateTimePicker') then alias := 'TDateTimePicker'
else if IsInheritsByclassName(clasName, 'TCustomListView') then alias := 'TListView'
else if IsInheritsByclassName(clasName, 'TCustomTreeView') then alias := 'TTreeView'
else alias := 'Default';
end;
End;
End;
if alias <> '' then Aliases[n] := clasName + '=' + alias;
End;
end;
end;
Function TResourceInfo.GetAlias (ClasName:AnsiString):AnsiString;
var
n:Integer;
Begin
Result:='';
for n := 0 to Aliases.Count-1 do
if SameText(ClasName, Aliases.Names[n]) then
begin
Result:=Aliases.Values[ClasName];
Exit;
end;
end;
Function TResourceInfo.GetFormIdx (FormName:AnsiString; Var idx:Integer):TDfm;
var
n:Integer;
Begin
for n := 0 to FormList.Count-1 do
begin
Result:= TDfm(FormList[n]);
//Find form
if SameText(Result.Name, FormName) then
begin
idx := n;
Exit;
End;
end;
idx := -1;
Result:=Nil;
end;
Function TResourceInfo.GetFormByClassName (ClasName:AnsiString):TDfm;
var
n:Integer;
Begin
for n := 0 to FormList.Count-1 do
begin
Result:= TDfm(FormList[n]);
//Find form
if SameText(Result.FormClass, ClasName) then Exit;
end;
Result:=Nil;
end;
Procedure TResourceInfo.GetEventsList (FormName:AnsiString; Lst:TList);
var
i,j,k,m,n, r,dot:Integer;
item:PEventListItem;
recN, recN1:InfoRec;
dfm,parentDfm,dfm1:TDfm;
classAdr:Integer;
ev,ev1:TList;
eInfo,eInfo1:PEventInfo;
recM:PMethodRec;
cInfo,cInfo1:PComponentInfo;
methodName,moduleName,actionName:AnsiString;
Begin
dfm := GetFormIdx(FormName, n);
if dfm=Nil then Exit;
classAdr := GetClassAdr(dfm.FormClass);
if IsValidImageAdr(classAdr) then recN := InfoList[Adr2Pos(classAdr)]
Else recN:=Nil;
//Form
//Inherited - begin fill list
if (dfm.Flags and FF_INHERITED)<>0 then
begin
parentDfm := GetParentDfm(dfm);
if Assigned(parentDfm) then
begin
GetEventsList(parentDfm.Name, Lst);
//int evCount := Lst.Count;
//evCount := evCount;
end;
end;
if dfm.Events.Count<>0 then
begin
ev := dfm.Events;
for k := 0 To ev.Count-1 do
begin
eInfo := ev[k];
New(item);
item.CompName := FormName;
item.EventName := eInfo.EventName;//eInfo.ProcName;
//Èùåì àäðåñ ñîîòâåòñòâóþùåãî ìåòîäà
recM := FMain.GetMethodInfo(recN, dfm.FormClass + '.' + eInfo.ProcName);
if Assigned(recM) then item.Adr := Integer(recM) Else item.Adr:= 0;
Lst.Add(item);
End;
End;
//Components
for m := 0 to dfm.Components.Count-1 do
begin
cInfo := dfm.Components[m];
if cInfo.Events.Count=0 then continue;
ev := cInfo.Events;
for k := 0 to ev.Count-1 do
begin
recN1 := recN;
eInfo := ev[k];
New(item);
item.CompName := cInfo.Name;
item.EventName := eInfo.EventName;//eInfo.ProcName;
methodName := '';
//Action
if SameText(eInfo.EventName, 'Action') then
begin
//Name eInfo.ProcName like FormName.Name
dot := Pos('.',eInfo.ProcName);
if dot<>0 then
begin
moduleName := Copy(eInfo.ProcName,1, dot - 1);
actionName := Copy(eInfo.ProcName,dot + 1, Length(eInfo.ProcName) - dot);
//Find form moduleName
for j := 0 to FormList.Count-1 do
begin
dfm1 := TDfm(FormList[j]);
if SameText(dfm1.Name, moduleName) then
begin
classAdr := GetClassAdr(dfm1.FormClass);
if IsValidImageAdr(classAdr) then recN1 := InfoList[Adr2Pos(classAdr)]
else recN1 := Nil;
//Find component actionName
for r := 0 to dfm1.Components.Count-1 do
begin
cInfo1 := dfm1.Components[r];
if SameText(cInfo1.Name, actionName) then
begin
//Find event OnExecute
ev1 := cInfo1.Events;
for i := 0 to ev1.Count-1 do
begin
eInfo1 := ev1[i];
if SameText(eInfo1.EventName, 'OnExecute') then
begin
methodName := dfm1.FormClass + '.' + eInfo1.ProcName;
break;
End;
End;
break;
end;
end;
break;
end;
end;
end
else
begin
//Find component eInfo.ProcName
for r := 0 to dfm.Components.Count-1 do
begin
cInfo1 := dfm.Components[r];
if SameText(cInfo1.Name, eInfo.ProcName) then
begin
//Find event OnExecute
ev1 := cInfo1.Events;
for i := 0 to ev1.Count-1 do
begin
eInfo1 := ev1[i];
if SameText(eInfo1.EventName, 'OnExecute') then
begin
methodName := dfm.FormClass + '.' + eInfo1.ProcName;
break;
end;
End;
break;
end;
end;
end;
end
else methodName := dfm.FormClass + '.' + eInfo.ProcName;
//Find method address
recM := FMain.GetMethodInfo(recN1, methodName);
if Assigned(recM) then item.Adr := Integer(recM) else recM.address := 0;
Lst.Add(item);
End;
End;
end;
Constructor TComponentEvents.Create (Owner:TCollection);
Begin
Inherited;
FoundEvents:=TStringList.Create;
FoundEvents.Sorted:=True;
end;
Destructor TComponentEvents.Destroy;
Begin
FoundEvents.Free;
Inherited;
end;
Constructor IdrDfmForm.Create (AOwner:TComponent);
Begin
Inherited;
evPopup:=TPopupMenu.Create(Nil);
evPopup.AutoPopup:=False;
evPopup.AutoHotkeys:=maManual;
KeyPreview:=True;
end;
Constructor IdrDfmForm.Create2(AOwner:TComponent; Dummy:Integer);
Begin
Inherited Create(Owner);
evPopup:=TPopupMenu.Create(Nil);
evPopup.AutoPopup:=False;
evPopup.AutoHotkeys:=maManual;
KeyPreview:=True;
end;
Destructor IdrDfmForm.Destroy;
Begin
compsEventsList.Free;
compsEventsList := Nil;
evPopup.Free;
frmTree.Free;
frmTree := Nil;
Inherited;
end;
Procedure IdrDfmForm.SetDesigning (value, SetChildren:Boolean);
Begin
inherited;
end;
Procedure IdrDfmForm.CreateHandle;
Begin
if FormStyle = fsMDIChild then FormStyle := fsNormal
Else Inherited;
end;
//this is required action as sometimes ShortCut from target exe could be same as ours...
Procedure IdrDfmForm.SetupControlResetShortcut (component:TComponent);
Begin