-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPJShellFoldersDsgn.pas
147 lines (120 loc) · 4.12 KB
/
PJShellFoldersDsgn.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
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2003-2014, Peter Johnson (www.delphidabbler.com).
*
* Component registration code and property editor for TPJBrowseDialog and
* TPJSpecialFolderInfo components defined in PJShellFolders.pas.
}
unit PJShellFoldersDsgn;
interface
// Determine compiler
{$UNDEF DELPHI6ANDUP}
{$UNDEF RTLNameSpaces} // Don't qualify RTL units names with namespaces
{$IFDEF CONDITIONALEXPRESSIONS}
{$IF CompilerVersion >= 24.0} // Delphi XE3 and later
{$LEGACYIFEND ON} // NOTE: this must come before all $IFEND directives
{$IFEND}
{$IF CompilerVersion >= 23.0} // Delphi XE2 and later
{$DEFINE RTLNameSpaces}
{$IFEND}
{$IF CompilerVersion >= 14.0} // Delphi 6 and later
{$DEFINE DELPHI6ANDUP}
{$IFEND}
{$ENDIF}
uses
{$IFNDEF RTLNameSpaces}
// Delphi
Classes,
{$ELSE}
System.Classes,
{$ENDIF}
{$IFDEF DELPHI6ANDUP}
DesignIntf, DesignEditors;
{$ELSE}
DsgnIntf;
{$ENDIF}
type
{
TPJFolderIDPE:
Property editor for special folder ID properties. Permits choice of
predefined special folders IDs.
}
TPJFolderIDPE = class(TPropertyEditor)
public
function GetAttributes: TPropertyAttributes; override;
{Tell object inspector that a list of read only values should be
displayed}
procedure GetValues(Proc: TGetStrProc); override;
{Returns all available folder ids for display in drop-down list}
procedure SetValue(const Value: string); override;
{Returns actual numeric value for given folder id constant}
function GetValue: string; override;
{Returns the name of the folder id constant for the given identifier
value}
end;
procedure Register;
{Delphi component library registration routine}
implementation
uses
{$IFNDEF RTLNameSpaces}
// Delphi
SysUtils, ShlObj,
{$ELSE}
System.SysUtils, Winapi.ShlObj,
{$ENDIF}
// Project
PJShellFolders;
// -----------------------------------------------------------------------------
// TPJFolderIDPE
// -----------------------------------------------------------------------------
function TPJFolderIDPE.GetAttributes: TPropertyAttributes;
{Tell object inspector that a list of read only values should be displayed}
begin
Result := [paValueList];
end;
function TPJFolderIDPE.GetValue: string;
{Returns the name of the folder id constant for the given identifier value}
begin
Result := SpecialFolderIDToStr(GetOrdValue);
end;
procedure TPJFolderIDPE.GetValues(Proc: TGetStrProc);
{Returns all available folder ids for display in drop-down list}
var
Enum: IPJSpecialFolderEnum; // enumerator for folder ids
begin
Enum := TPJSpecialFolderEnum.Create;
Enum.Init;
while not Enum.AtEnd do
Proc(SpecialFolderIdToStr(Enum.Next));
end;
procedure TPJFolderIDPE.SetValue(const Value: string);
{Returns actual numeric value for given folder id constant}
begin
SetOrdValue(StrToSpecialFolderID(Value));
end;
// -----------------------------------------------------------------------------
// Delphi registration routine
// -----------------------------------------------------------------------------
procedure Register;
{Registers components and property editor with Delphi}
begin
// Register the unit's components
RegisterComponents('DelphiDabbler', [TPJSpecialFolderInfo, TPJBrowseDialog]);
// Register special folder id property editor:
// .. for TPJSpecialFolderInfo.FolderID
RegisterPropertyEditor(
TypeInfo(Integer), // type information about property we edit
TPJSpecialFolderInfo, // work with component of this type
'FolderID', // only for use with this property
TPJFolderIDPE); // property editor class
// .. for TPJBrowseDlg.RootFolderID
RegisterPropertyEditor(
TypeInfo(Integer), // type information about property we edit
TPJBrowseDialog, // work with component of this type
'RootFolderID', // only for use with this property
TPJFolderIDPE); // property editor class
end;
end.