forked from Sovos-Compliance/convey-public-libs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
INIPROPS.PAS
2425 lines (2287 loc) · 78.7 KB
/
INIPROPS.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
{ If you have problems compiling this package when trying to install it in Delphi 4
because the compiler says that ComServ cannot be included in the Package
try activating the next directive adding the $ sign after the { sign.
Don't forget to delete the $ sign after installing the package, it's only
required when compiling for DesignTime }
{Define DESIGNTIME}
{$IFDEF VER180}
{$Define D4and5}
{$Define D10}
{$Define Ver130}
{$Else}
{$IfDef Ver130}
{$Define D4and5}
{$Else}
{$IFDef Ver120}
{$Define D4and5}
{$EndIf}
{$EndIf}
{$ENDIF}
unit Iniprops;
interface
{
TINIPropSav - version 2.21
Copyright 1997-1998 - José Sebastián Battig - Maiten Desarrollos Informaticos
E-Mail: [email protected]
Please read the notes.txt file
}
{$IfDef Win32}
{Define DemoVersion} { If you have the registered version please delete this directive }
{$EndIf}
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, INIFiles, TypInfo,
{$IFDef VER180} DesignIntf, DesignEditors, VCLEditors {$Else} DsgnIntf {$EndIf}, Menus {$IfDef Win32} , ExtIni, Registry {$EndIf};
type
{$IFDef D10}
IFormDesigner = IDesigner;
{$EndIf}
TAutoLoad = (aldNone, aldBeforeOnCreateForm, aldBeforeOnShowForm, aldAfterOnCreateForm, aldAfterOnShowForm);
TAutoSave = (asvNone, asvBeforeOnDestroyForm, asvBeforeOnHideForm, asvAfterOnDestroyForm, asvAfterOnHideForm);
TSpecialProperties = (npInteger, npEnumeration, npFloat); { Added in version 1.3 }
TSpecialPropertiesSet = set of TSpecialProperties; { Added in version 1.3 }
TPropertyWork = procedure (Sender : TObject; Component : TComponent; const PropName : string) of object;
TPropertyError = procedure (Sender : TObject; Component : TComponent;
const PropName, Value : string; E : Exception) of object;
TINIPropSav = class(TComponent)
private
{$IfDef Win32}
FINIFile : TExtINIFile;
{$Else}
FINIFile : TINIFile;
{$EndIf}
FUseAppDir : boolean;
FFileName : PString;
FSavedProperties : TStrings;
FSections : TStrings;
FLoadProperty : TPropertyWork;
FSaveProperty : TPropertyWork;
FLoadError : TPropertyError;
FSaveError : TPropertyError;
MustLoad : boolean;
FAutoLoad : TAutoLoad;
FAutoSave : TAutoSave;
OnLoad : TNotifyEvent;
OnSave : TNotifyEvent;
AutoOpened : boolean;
{$IFDef D10}
FCachedComponent: TComponent;
{$Endif}
ToBind : TStringList;
ToBindMethods : TStringList;
SubPropsStack : TList;
FStoreAsRaw : TSpecialPropertiesSet; { Added in version 1.3 }
FStartLoadingProperties : TNotifyEvent; { Added in version 2.2 }
FEndLoadingProperties : TNotifyEvent; { Added in version 2.2 }
FStartSavingProperties : TNotifyEvent; { Added in version 2.2 }
FEndSavingProperties : TNotifyEvent; { Added in version 2.2 }
{$IfDef Win32}
FEncrypted : boolean; { Added in version 2.1}
FUseRegistry : boolean; { New in version 1.1 }
FCompanyName : string; { New in version 1.1 }
FProductName : string; { New in version 1.1 }
FRootKey : HKEY; { Added in version 1.21 }
FUseSoftwareKey : boolean; { Added in version 1.21 }
FLazyWrite : boolean; { Added in version 1.22 }
{$EndIf}
procedure ReOpen;
procedure SetSavedProperties (AProp : TStrings);
procedure SetSections (ASecc : TStrings);
procedure SetFileName (const AName : string);
function GetFileName : string;
procedure SetUseAppDir (Value : boolean);
procedure ReadProperties (Reader : TReader);
procedure WriteProperties (Writer : TWriter);
procedure ReadSections (Reader : TReader);
procedure WriteSections (Writer : TWriter);
procedure UpdateObjects;
procedure PropertyWork ({$IFDef D10}const {$EndIf}Prop : {$IFDef D10}IProperty{$Else}TPropertyEditor{$Endif});
procedure PropertiesWork;
function GetIsOpen : boolean;
function GetSavedComponentsCount : integer;
function GetSavedComponents (Index : integer) : TComponent;
function GetSavedProperties (Index : integer) : string;
function GetSections (Component : TComponent; const Prop : string) : string;
procedure SetSections2 (Component : TComponent; const Prop, Secc : string);
function GetIdentifiers (Component : TComponent; const Prop : string) : string;
procedure SetIdentifiers (Component : TComponent; const Prop, Ident : string);
function GetMustLoad (Component : TComponent; const Prop : string) : boolean;
procedure SetMustLoad (Component : TComponent; const Prop : string; Value : boolean);
function GetMustSave (Component : TComponent; const Prop : string) : boolean;
procedure SetMustSave (Component : TComponent; const Prop : string; Value : boolean);
procedure GetSubProperties ({$IFDef D10}const {$Endif}Prop : {$IFDef D10} IProperty {$Else} TPropertyEditor {$EndIf});
procedure AutoLoadEvent (Sender : TObject);
procedure AutoSaveEvent (Sender : TObject);
procedure WriteAutoSave (Value : TAutoSave);
procedure WriteAutoLoad (Value : TAutoLoad);
procedure AssignSave (Form : TForm);
procedure AssignLoad (Form : TForm);
function AssignPath (const AFileName : string) : string;
function PrepareCompRef (CompRef : TComponent; var Value : string) : TComponent;
procedure BindReferences (List : TStringList; Tipo : TTypeKind);
procedure SetStoreAsRaw (value : TSpecialPropertiesSet); { Added in version 1.3 }
{$IfDef Win32}
procedure SetUseRegistry (value : boolean); { Added in version 1.1 }
procedure SetRootKey (value : HKEY); { Added in version 1.21 }
procedure SetLazyWrite (value : boolean); { Added in version 1.22 }
function GetRegINIFile : TRegINIFile; { Added in version 1.22 }
procedure SetEncrypted (AEncrypted : boolean);
{$EndIf}
function GetINIFile : TINIFile; { Added in version 1.22 }
protected
procedure Notification (AComponent : TComponent;
AOperation : TOperation); override;
procedure DefineProperties (Filer : TFiler); override;
procedure Loaded; override;
procedure UpdateNames (Remove : TComponent);
property Properties : TStrings read FSavedProperties write SetSavedProperties;
property Sections : TStrings read FSections write SetSections;
{ This function could be declared as a unit function, but i like to put it here because
i guess that only i'm interested in this function, and someone that want's to derive
this component, that's why is protected }
class function IsClass (Prop : {$IfDef D10}IProperty{$Else}TPropertyEditor{$EndIf}; Clase : TClass) : boolean;
public
constructor Create (AOwner : TComponent); override;
destructor Destroy; override;
procedure EraseSection (const Section : string);
procedure ReadSection (const Section : string; Values : TStrings);
function ReadBool (const Section, Ident : string; Default : boolean) : boolean;
procedure WriteBool (const Section, Ident : string; Value : boolean);
function ReadInteger (const Section, Ident : string; Default : integer) : integer;
procedure WriteInteger (const Section, Ident : string; Value : integer);
function ReadString (const Section, Ident, Default : string) : string;
procedure WriteString (const Section, Ident, Value : string);
procedure ReadSectionValues (const Section : string; Values : TStrings);
procedure OpenFile;
procedure CloseFile;
procedure LoadProperties;
procedure SaveProperties;
function IndexOf (Component : TComponent; const Prop : string) : integer;
property IsOpen : boolean read GetIsOpen;
property SavedComponentsCount : integer read GetSavedComponentsCount;
property SavedComponents [Index : integer] : TComponent read GetSavedComponents;
property SavedProperties [Index : integer] : string read GetSavedProperties;
property INISections [Component : TComponent; const Prop : string] : string read GetSections write SetSections2;
property INIIdentifiers [Component : TComponent; const Prop : string] : string read GetIdentifiers write SetIdentifiers;
property MustLoadProperty [Component : TComponent; const Prop : string] : boolean read GetMustLoad write SetMustLoad;
property MustSaveProperty [Component : TComponent; const Prop : string] : boolean read GetMustSave write SetMustSave;
{$IfDef Win32}
property RegINIFile : TRegINIfile read GetRegINIFile; { Added in version 1.22 }
{$EndIf}
property INIFile : TINIFile read GetINIFile; { Added in version 1.22 }
published
property FileName : string read GetFileName write SetFileName; { In version 1.1 this property is updated when the
registry file is opened, so you have not to make assumptions
about it's value. Check the OpenFile Method to see how and
when is changed. }
property UseAppDir : boolean read FUseAppDir write SetUseAppDir default true;
property AutoLoadProperties : TAutoLoad read FAutoLoad write WriteAutoLoad default aldAfterOnCreateForm;
property AutoSaveProperties : TAutoSave read FAutoSave write WriteAutoSave default asvBeforeOnDestroyForm;
property StoreAsRawData : TSpecialPropertiesSet read FStoreAsRaw write SetStoreAsRaw; { Added in version 1.3 }
property OnLoadProperty : TPropertyWork read FLoadProperty write FLoadProperty;
property OnSaveProperty : TPropertyWork read FSaveProperty write FSaveProperty;
property OnLoadPropertyError : TPropertyError read FLoadError write FLoadError;
property OnSavePropertyError : TPropertyError read FSAveError write FSaveError;
property OnStartLoadingProperties : TNotifyEvent read FStartLoadingProperties write FStartLoadingProperties; { ver 2.2 }
property OnEndLoadingProperties : TNotifyEvent read FEndLoadingProperties write FEndLoadingProperties; { ver 2.2 }
property OnStartSavingProperties : TNotifyEvent read FStartSavingProperties write FStartSavingProperties; { ver 2.2 }
property OnEndSavingProperties : TNotifyEvent read FEndSavingProperties write FEndSavingProperties; { ver 2.2 }
{$IfDef Win32}
property Encrypted : boolean read FEncrypted write SetEncrypted default false; { Added in version 2.1 }
property UseRegistry : boolean read FUseRegistry write SetUseRegistry default false; { Added in version 1.1 }
property CompanyName : string read FCompanyName write FCompanyName; { Added in version 1.1 }
property ProductName : string read FProductName write FProductName; { Added in version 1.1 }
property RootKey : HKEY read FRootKey write SetRootKey default HKEY_CURRENT_USER; { Added in version 1.21 }
property UseSoftwareKey : boolean read FUseSoftwareKey write FUseSoftwareKey default true; { Added in version 1.21 }
property LazyWrite : boolean read FLazyWrite write SetLazyWrite default true; { Added in version 1.22 }
{$EndIf}
end;
{ Error messages used in conjunction with EINIPropSav... if you want to change it.... }
const
INIProblems : string = 'There are problems with the INI/Registry file';
PropNotFind : string = 'Property don''t found';
NoComponentError : string = 'Cannot solve component reference of a non-component class';
type
EINIPropSav = class (Exception)
{ Nothing special }
end;
{ These are utility functions for parse the info stored in the component, if you derive the
component and you want to do some special management of the stored information you can use
this functions }
function INIpQuote (const s : string) : string;
function INIpUnQuote (const s : string) : string;
function StringForList (const Comp, Prop : string) : string;
function SeccionForList (const Comp, Prop : string;
Seccion, Item, Value : string;
Guardar, Cargar : boolean) : string; { To much parameters no??...
do you remember structured programming ??? :) }
function ExtractSeccion (const Cad : string) : string;
function ExtractItem (const Cad : string) : string;
function ExtractValue (const Cad : string) : string;
function ExtractComponent (const Cad : string) : string;
function ExtractProperty (const Cad : string) : string;
function ExtractGuardar (const Cad : string) : boolean; { Sorry by the name, Guardar = "to Save" in english }
function ExtractCargar (const Cad : string) : boolean; { Cargar = "to Load" in english }
{ Encryption utility functions... are not big deal, but it serve to our purpose to hide
information in the Registry or ini files }
{$IfDef Win32}
procedure Encrypt (var Data; Size : cardinal; Basic : boolean);
procedure Decrypt (var Data; Size : cardinal; Basic : boolean);
type
HKEYArray = array [HKEY_CLASSES_ROOT..HKEY_DYN_DATA] of string;
const
HKEYS : HKEYArray = ('HKEY_CLASSES_ROOT', 'HKEY_CURRENT_USER',
'HKEY_LOCAL_MACHINE', 'HKEY_USERS', 'HKEY_PERFORMANCE_DATA',
'HKEY_CURRENT_CONFIG', 'HKEY_DYN_DATA');
{ These two functions are used to map strings to HKEY numeric constants
to strings, both functions are registered in the initialization part of this unit }
function HKEYToIdent (aint : longint; var Ident : string) : boolean;
function IdentToHKEY (const Ident : string; var Int : longint) : boolean;
{$EndIf}
implementation
{$IFDef DemoVersion}
{$IfDef D4and5}
uses
TempStr, CryptSt, TlHelp32, ComObj, {$IfNDef DESIGNTIME}, ComServ {$EndIf};
{$Else}
uses
TempStr, CryptSt, TlHelp32;
{$EndIf}
{$Else}
{$IfDef Ver80}
uses
TrimFunc;
{$Else}
{$IfDef D4and5}
uses
TempStr, CryptSt, ComObj {$IFNDef DESIGNTIME}, ComServ {$EndIf};
{$Else}
uses
TempStr, CryptSt;
{$EndIf}
{$EndIf}
{$EndIf}
const
PropsToCheck : set of TTypeKind = [tkInteger, tkEnumeration, tkFloat];
{$IfDef Ver100}
Registered : boolean = false;
{$EndIf}
{$IfDef D4and5}
Registered : boolean = false;
{$EndIf}
function ToSpecialProperties (value : TTypeKind) : TSpecialProperties;
begin
case value of
tkInteger : Result := npInteger;
tkEnumeration : Result := npEnumeration;
tkFloat : Result := npFloat;
else raise Exception.Create ('No se puede convertir de TTypeKind a TSpecialProperties');
end;
end;
type
{ Here the expose trick again... i hope that in D3 GetOrdValue continue being not virtual }
TExposePropertyEditor = class (TPropertyEditor)
public
{
procedure Activate; override;
function GetOrdValue : longint;
procedure SetOrdValue (value : longint);
function GetFloatValue : double;
procedure SetFloatValue (value : double);}
end;
{function TExposePropertyEditor.GetOrdValue;
begin
Result := inherited GetOrdValue;
end;
procedure TExposePropertyEditor.SetOrdValue;
begin
inherited SetOrdValue (Value);
end;
function TExposePropertyEditor.GetFloatValue;
begin
Result := inherited GetFloatValue;
end;
procedure TExposePropertyEditor.SetFloatValue;
begin
inherited SetFloatValue (Value);
end;}
{ You will ask why I commented out all the code in TExposePropertyEditor... well, simply
because I accidentaly discovered that when you create a new class in a unit and cast
the object you want to access protected stuff to this newly created class, then you have
access to all protected stuff without re-writing this stuff in your new class. Nice trick
to fool encapsulation. This works fine in Delphi 2 as well as Delphi 3, I had no chance to
try it in Delphi 4. So, I decided to delete all this useless code to avoid more overhead,
but I let it there just to show the diference. }
{$IfDef DemoVersion}
const
MsgShowed : boolean = false;
{$EndIf}
type
{ This class is used in cojuntion with the GetPropertiesProcedure for set the
properties values when reading from the Ini file or the registry }
{$IfDef D4and5}
TMyDesigner = class (TComObject, IFormDesigner)
{$Else}
TMyDesigner = class (TFormDesigner)
{$EndIf}
{$IfDef D4and5}
procedure Modified;
procedure Notification(AnObject: TPersistent; Operation: TOperation);
function GetCustomForm: TCustomForm;
procedure SetCustomForm(Value: TCustomForm);
function GetIsControl: Boolean;
procedure SetIsControl(Value: Boolean);
function IsDesignMsg(Sender: TControl; var Message: TMessage): Boolean;
procedure PaintGrid;
procedure ValidateRename(AComponent: TComponent;
const CurName, NewName: string);
function CreateMethod(const Name: string; TypeData: PTypeData): TMethod;
{$IfDef D10}
overload;
function CreateMethod(const Name: string; const AEventInfo: IEventInfo): TMethod; overload;
{$EndIf}
function GetMethodName(const Method: TMethod): string;
procedure GetMethods(TypeData: PTypeData; Proc: TGetStrProc);
{$IfDef D10}
overload;
procedure GetMethods(const AEventInfo: IEventInfo; Proc: TGetStrProc); overload;
{$EndIf}
function GetPrivateDirectory: string;
procedure GetSelections(const List: IDesignerSelections);
function MethodExists(const Name: string): Boolean;
procedure RenameMethod(const CurName, NewName: string);
procedure SelectComponent(Instance: TPersistent);
{$IFDef D10}
overload;
procedure SelectComponent(const ADesignObject: IDesignObject); overload;
{$EndIf}
procedure SetSelections(const List: IDesignerSelections);
procedure ShowMethod(const Name: string);
function UniqueName(const BaseName: string): string;
procedure GetComponentNames(TypeData: PTypeData; Proc: TGetStrProc);
function GetComponent(const Name: string): TComponent;
function GetComponentName(Component: TComponent): string;
function GetObject(const Name: string): TPersistent;
function GetObjectName(Instance: TPersistent): string;
procedure GetObjectNames(TypeData: PTypeData; Proc: TGetStrProc);
function MethodFromAncestor(const Method: TMethod): Boolean;
function CreateComponent(ComponentClass: TComponentClass; Parent: TComponent;
Left, Top, Width, Height: Integer): TComponent;
function IsComponentLinkable(Component: TComponent): Boolean;
procedure MakeComponentLinkable(Component: TComponent);
function GetRoot: TComponent;
procedure Revert(Instance: TPersistent; PropInfo: PPropInfo);
function GetIsDormant: Boolean;
function HasInterface: Boolean;
function HasInterfaceMember(const Name: string): Boolean;
procedure AddToInterface(InvKind: Integer; const Name: string; VT: Word;
const TypeInfo: string);
procedure GetProjectModules(Proc: TGetModuleProc);
function GetAncestorDesigner: IFormDesigner;
function IsSourceReadOnly: Boolean;
{$Else}
procedure Modified; override;
{$EndIf}
{$IfDef Ver130}
function GetContainerWindow: TWinControl;
procedure SetContainerWindow(const NewContainer: TWinControl);
function GetScrollRanges(const ScrollPosition: TPoint): TPoint;
procedure Edit(const Component: {$IFDEF D10} TComponent {$Else}IComponent{$Endif});
{$IfNDef D10}
function BuildLocalMenu(Base: TPopupMenu; Filter: TLocalMenuFilters): TPopupMenu;
{$EndIf}
procedure ChainCall(const MethodName, InstanceName, InstanceMethod: string;
TypeData: PTypeData);
{$IfDef D10} overload;
procedure ChainCall(const MethodName, InstanceName, InstanceMethod: string;
const AEventInfo: IEventInfo); overload;
{$EndIf}
procedure CopySelection;
procedure CutSelection;
function CanPaste: Boolean;
procedure PasteSelection;
procedure DeleteSelection {$IFDef D10} (ADoAll: Boolean = False) {$Endif};
procedure ClearSelection;
procedure NoSelection;
procedure ModuleFileNames(var ImplFileName, IntfFileName, FormFileName: string);
function GetRootClassName: string;
{$EndIf}
{$IFDEF D10}
function IsComponentHidden(Component: TComponent): Boolean;
function GetBaseRegKey: string;
function GetIDEOptions: TCustomIniFile;
function GetPathAndBaseExeName: string;
procedure Activate;
function CreateCurrentComponent(Parent: TComponent; const Rect: TRect): TComponent;
function GetShiftState: TShiftState;
procedure ModalEdit(EditKey: Char; const ReturnWindow: IActivatable);
procedure SelectItemName(const PropertyName: string);
procedure Resurrect;
function GetActiveClassGroup: TPersistentClass;
function FindRootAncestor(const AClassName: string): TComponent;
procedure PaintMenu;
function GetDesignerExtension: string;
{$EndIf}
end;
{$IfDef D4and5}
{$IfNDef DESIGNTIME}
const
Class_TMyDesigner : TGUID = '{B9DD0AD2-84A0-11D2-8E06-00104BECB272}';
{$EndIf}
{$i EmptyDesigner.inc}
{$EndIf}
var
SubProps : string; { This global variable is here because i had problems
when it was declared inside the class because it was used
in a CallBack function...a rare problem... }
{$IfDef DemoVersion}
{ This is the code segment that preforms the shareware control... the idea is very
simple. Check for a process called delphi32.exe, and then in that process check
for a module with the extension .DCL, if that's true then delphi is loaded into
memory...., if only delphi32.exe is in memory could be because the DCL load operation
failed... or because someone is trying to fool this component }
function GetProcessId (const Nombre : string) : DWORD;
var
Module : TProcessEntry32;
h : THandle;
proc : string;
Found : boolean;
begin
Found := false;
Result := 1;
h := CreateToolhelp32SnapShot (TH32CS_SNAPALL, 0);
try
Module.dwSize := sizeof (Module);
if Process32First (h, Module)
then repeat
Proc := StrPas (Module.szExeFile);
if UpperCase (Nombre) = UpperCase (copy (Proc, length (Proc) - length (Nombre) + 1, length (Nombre)))
then
begin
Result := Module.th32ProcessId;
Found := true;
break;
end;
until not Process32Next (h, Module);
finally
CloseHandle (h);
end;
if not Found
then raise Exception.Create ('Process not found');
end;
function CheckShare : boolean;
var
Module : TModuleEntry32;
h : THandle;
id : DWORD;
Modulo : string;
begin
Result := false;
try
id := GetProcessId ('DELPHI32.EXE')
except
exit;
end;
h := CreateToolhelp32SnapShot (TH32CS_SNAPALL, id);
try
Fillchar (Module, sizeof (Module), 0);
Module.dwSize := sizeof (Module);
if Module32First (h, Module)
then repeat
Modulo := StrPas (Module.szExePath);
{$IfDef Ver90}
if UpperCase (ExtractFileExt (Modulo)) = '.DCL'
{$Endif}
{$IfDef Ver100}
if UpperCase (ExtractFileName (Modulo)) = 'INIPROPS.DPL'
{$EndIf}
{$IfDef D4and5}
if UpperCase (ExtractFileName (Modulo)) = 'INIPROPS.DPL'
{$EndIf}
then
begin
Result := true;
break;
end;
until not Module32Next (h, Module);
finally
CloseHandle (h);
end;
end;
{$EndIf} { DemoVersion }
{ TINIPropSav }
constructor TINIPropSav.Create;
begin
inherited Create (AOwner);
FIniFile := nil;
FFileName := nil;
FSavedProperties := TStringList.Create;
FSections := TStringList.Create;
FUseAppDir := true;
FAutoLoad := aldAfterOnCreateForm;
FAutoSave := asvBeforeOnDestroyForm;
FStoreAsRaw := [];
{$IfDef Win32}
FRootKey := HKEY_CURRENT_USER;
FUseSoftwareKey := true;
FLazyWrite := true;
{$EndIf}
{ I have to do the folowing to avoid an access violation error in Delphi 3, Delphi 3
changes the way to manage the property editors. In runtime, there's a nil pointer
that when is referenced to access a list of property editors an exception is raised.
When you register a property editor the list is created avoiding that problem }
{$IFDef Ver100}
if (not Registered) and (not (csDesigning in ComponentState))
then
begin
{ I reegister a non existent property... but I don't care that, i just care to
avoid the error }
RegisterPropertyEditor (TypeInfo (TFont), TINIPropSav, 'Font', TFontProperty);
Registered := true;
end;
{$EndIf}
{$IfDef D4and5}
if (not Registered) and (not (csDesigning in ComponentState))
then
begin
{ I register a non existent property... but I don't care that, i just care to
avoid the error }
RegisterPropertyEditor (TypeInfo (TFont), TINIPropSav, 'Font', TFontProperty);
Registered := true;
end;
{$EndIf}
end;
destructor TINIPropSav.Destroy;
begin
FSavedProperties.Clear;
FSavedProperties.Free;
FSections.Free;
CloseFile;
DisposeStr (FFileName); { PString used for FFileName for compatibility with D1,
this uses the exact needed memory in D1 that just "string" }
inherited Destroy;
end;
{ Method added in version 1.1 }
{$IfDef Win32}
procedure TINIPropSav.SetEncrypted;
begin
if AEncrypted <> FEncrypted
then
begin
if AEncrypted
then if FUseRegistry
then FEncrypted := AEncrypted
else if csDesigning in ComponentState
then if not (csLoading in ComponentState)
then raise Exception.Create ('Cannot set the Encrypted property to true if UseRegistry is false')
else FEncrypted := AEncrypted
else if csLoading in ComponentState
then FEncrypted := AEncrypted
else {}
else FEncrypted := AEncrypted;
end;
end;
procedure TINIPropSav.SetUseRegistry;
begin
if value <> FUseRegistry
then
begin
FUseRegistry := value;
if not FUseRegistry
then FEncrypted := false;
if FIniFile <> nil
then CloseFile;
end;
end;
{ Method added in version 1.21 }
procedure TINIPropSav.SetRootKey;
begin
FRootKey := Value;
if FIniFile <> nil
then FINIFile.RootKey := FRootKey;
end;
{ Methods added in version 1.22 }
function TINIPropSav.GetRegINIFile;
begin
if FIniFile <> nil
then Result := FINIFile.RegINIFile
else Result := nil;
end;
procedure TINIPropSav.SetLazyWrite;
begin
FLazyWrite := value;
if FINIFile <> nil
then FINIFile.LazyWrite := FLazyWrite;
end;
{$EndIf}
function TINIPropSav.GetINIFile;
begin
{$IFDef Win32}
if FINIFile <> nil
then Result := FINIFile.INIFile
else Result := nil;
{$Else}
Result := FINIFile;
{$EndIf}
end;
procedure TINIPropSav.SetStoreAsRaw;
begin
if Value <> FStoreAsRaw
then
begin
FStoreAsRaw := Value;
{$IfDef Win32}
if FINIFile <> nil
then
begin
FINIFile.StoreIntegerAsRaw := npInteger in FStoreAsRaw;
FINIFile.StoreFloatAsRaw := npFloat in FStoreAsRaw;
end;
{$EndIf}
end;
end;
procedure TINIPropSav.AutoLoadEvent;
begin
if FAutoLoad <> aldNone
then if FAutoLoad in [aldBeforeOnCreateForm, aldBeforeOnShowForm]
then
begin
try
LoadProperties;
finally
if assigned (OnLoad)
then OnLoad (Sender);
end;
end
else
begin
if assigned (OnLoad)
then OnLoad (Sender);
LoadProperties;
end
else if assigned (OnLoad)
then OnLoad (Sender);
end;
procedure TINIPropSav.AutoSaveEvent;
begin
if FAutoSave <> asvNone
then if FAutoSave in [asvAfterOnDestroyForm, asvAfterOnHideForm]
then
begin
if assigned (OnSave)
then OnSave (Sender);
SaveProperties;
end
else
begin
try
SaveProperties;
finally
if assigned (OnSave)
then OnSave (Sender);
end;
end
else if assigned (OnSave)
then OnSave (Sender);
end;
{ This method binds the references stored in the ini file, it lookups the owners until it finds the
final reference for a given component }
procedure TINIPropSav.BindReferences;
var
i, j : integer;
ObjName, PropName, Value : string;
Comp, Ref : TComponent;
Method : TMethod;
begin
for i := 0 to List.Count - 1 do
begin
Comp := TComponent (List.Objects [i]);
j := pos ('=', List [i]);
if j > 0
then
begin
PropName := copy (List [i], 1, j - 1);
Value := copy (List [i], j + 1, length (List [i]) - j);
end
else continue; { The error is ignored to continue fixing references }
if Value <> ''
{$IfNDef Ver80}
then Ref := Application { Starts the lookup by the Application object, the form reference MUST be present }
{$Else}
then Ref := Owner { In delphi 1 starts the lookup in the Form... that's the owner }
{$EndIf}
else
begin
Ref := nil;
SetOrdProp (Comp, GetPropInfo (Comp.ClassInfo, PropName), longint (Ref));
continue;
end;
while (Value <> '') and (Ref <> nil) do
begin
j := pos ('.', Value);
if j <= 0
then if Tipo <> tkMethod
then j := length (Value) + 1
else break;
ObjName := copy (Value, 1, j - 1);
Value := copy (Value, j + 1, length (Value) - j);
Ref := Ref.FindComponent (ObjName);
end;
if Ref <> nil
then if Tipo = tkClass
then SetOrdProp (Comp, GetPropInfo (Comp.ClassInfo, PropName), longint (Ref))
else
begin
if Value <> ''
then
begin
Method.Code := Ref.MethodAddress (Value);
Method.Data := Ref;
end
else
begin
Method.Code := nil;
Method.Data := nil;
end;
SetMethodProp (Comp, GetPropInfo (Comp.ClassInfo, PropName), Method);
end;
end;
end;
function TINIPropSav.PrepareCompRef;
begin
if CompRef <> nil
then
begin
if not (CompRef is TComponent)
then raise EINIPropSav.Create (NoComponentError);
while CompRef <> nil do
begin
Value := CompRef.Name + Value;
CompRef := CompRef.Owner;
if (CompRef <> nil) and {$IfNDef Ver80 }(CompRef <> Application) {$Else} (CompRef <> Owner) {$EndIf}
then Value := '.' + Value;
end;
end
else Value := '';
Result := CompRef;
end;
{ This is a callback method for properties that have subproperties,
like the font property }
procedure TINIPropSav.GetSubProperties;
var
p : integer;
Value : string;
CompRef : TComponent;
begin
try
if paSubProperties in Prop.GetAttributes
then
begin
SubPropsStack.Add (pointer (TExposePropertyEditor (Prop).GetOrdValue));
Prop.GetProperties (GetSubProperties);
SubPropsStack.Delete (SubPropsStack.Count - 1);
end
else if not MustLoad
then
begin
case Prop.GetPropType^.Kind of
tkClass : PrepareCompRef (TComponent (TExposePropertyEditor (Prop).GetOrdValue), Value);
tkMethod :
begin
CompRef := TComponent (TExposePropertyEditor (Prop).GetMethodValue.Data);
if CompRef <> nil
then
begin
PrepareCompRef (CompRef, Value);
if Value <> ''
then Value := Value + '.';
Value := Value + CompRef.MethodName (TExposePropertyEditor (Prop).GetMethodValue.Code);
if Value [length (Value)] = '.'
then Value := '';
end
else Value := '';
end;
else value := Prop.{$IFDef D10}GetValue{$else}Value{$Endif}
end;
if SubProps <> ''
then SubProps := SubProps + ', '+ Value
else SubProps := Value;
end
else
begin
p := pos (',', SubProps);
if p <> 0
then
begin
Value := Trim (copy (SubProps, 1, p - 1));
SubProps := copy (SubProps, p + 1, length (SubProps) - p);
end
else Value := SubProps;
case Prop.GetPropType^.Kind of
tkClass : ToBind.AddObject (Prop.GetName + '=' + Value, SubPropsStack [SubPropsStack.Count - 1]);
tkMethod : ToBindMethods.AddObject (Prop.GetName + '=' + Value, SubPropsStack [SubPropsStack.Count - 1]);
else Prop.{$IFDef D10}SetValue (Value){$else}Value := Value{$Endif};
end;
end;
finally
{ Added in version 1.12 You must free the property editors returned by
GetComponentProperties, they are owned by the Designer and in this case
the Designer is MY Designer, so the property editors belongs to me }
{$IFNDef D10}
Prop.Free;
{$EndIf}
end;
end;
{ This function is declared as class function because it's use in the unit iniprop.pas with
a actual object and for use this function we use the expose trick again. This function really
could be declared as a sole function... but dont has utility in the context of the class for
the end user of the class }
class function TINIPropSav.IsClass (Prop : {$IfDef D10}IProperty{$Else}TPropertyEditor{$Endif}; Clase : TClass) : boolean;
var
Obj : TObject;
begin
Result := false;
if Prop.GetPropType^.Kind = tkClass
then
begin
Obj := TObject (TExposePropertyEditor (Prop).GetOrdValue);
if Obj <> nil
then Result := Obj is Clase
end;
end;
{ This is the callback method of the function GetComponentProperties, this method is
used for the Load and the Save actions... this method is really big... }
procedure TINIPropSav.PropertyWork;
var
CompRef, CompTemp : TComponent;
Comp : TPersistent;
Secc : string;
Ident : string;
Index : integer;
CompName : string;
Cad, Value : string;
Strings: TStrings;
Cargar, Guardar : boolean;
AsLink : boolean;
Picture : TPicture;
Graphic : TGraphic;
IntegerValue : longint;
FloatValue : double;
{$IfNDef Ver80}
CryptStream : TEncryptedStream;
TempFile : TTempFileStream;
TempFileName, OldName : string;
{$EndIf}
{ These nested procedures where added in version 1.2}
procedure CalculateAsLink;
var
Cad2 : string;
begin
try
Cad2 := ExtractValue (Cad);
if Cad2 <> ''
then AsLink := boolean (StrToInt (Cad2))
else AsLink := false;
except
AsLink := false;
end;
end;
procedure LoadProperty;
var
LastRawInteger : boolean;
procedure ReadValue;
begin
{$IfDef Win32}
if FEncrypted and (length (Value) > 0)
then Encrypt (Value [1], length (Value), true);
{$EndIf}
Value := FINIFile.ReadString (Secc, Ident, Value);
{$IfDef Win32}
if FEncrypted and (length (Value) > 0)
then Decrypt (Value [1], length (Value), true);
{$EndIf}
end;
procedure ReadProperty;
begin
Value := Prop.{$IFDef D10}GetValue{$Else}Value{$EndIf};
ReadValue;
Prop.{$IFDef D10}SetValue (Value){$Else}Value := Value{$EndIf};
end;
begin
try
if Cargar
then if (not IsClass (Prop, TStrings)) and (not IsClass (Prop, TPicture)) and
(not IsClass (Prop, TGraphic))
then if not (Prop.GetPropType^.Kind in [tkClass, tkMethod])
then
begin
{ Code for read simple properties modified in version 1.3 to support Raw Data}
if Prop.GetPropType^.Kind in PropsToCheck
then if ToSpecialProperties (Prop.GetPropType^.Kind) in FStoreAsRaw
then case Prop.GetPropType^.Kind of
tkInteger :
begin
IntegerValue := TExposePropertyEditor (Prop).GetOrdValue;
{$IFDef Win32}
if FEncrypted
then Encrypt (IntegerValue, sizeof (IntegerValue), not (npInteger in FStoreAsRaw));
{$EndIf}
IntegerValue := FINIFile.ReadInteger (Secc, Ident, IntegerValue);
{$IfDef Win32}
if FEncrypted
then Decrypt (IntegerValue, sizeof (IntegerValue), not (npInteger in FStoreAsRaw));
{$EndIf}
Prop.{$IFDef D10}SetValue (IntToStr (IntegerValue)){$Else}Value := IntToStr (IntegerValue){$EndIf};
end;
tkEnumeration :
begin
{$IfDef Win32}