-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileContainerDesign.pas
92 lines (77 loc) · 1.77 KB
/
FileContainerDesign.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
unit FileContainerDesign;
interface
procedure Register;
implementation
uses
System.SysUtils,
System.Classes,
Vcl.Dialogs,
DesignIntf,
DesignMenus,
DesignEditors,
FileContainer;
type
TFileContainerEditor = class(TComponentEditor)
protected
{--- IComponentEditor --}
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
procedure DoLoad;
procedure DoSave;
procedure DoClear;
end;
procedure Register;
begin
ForceDemandLoadState(dlDisable);
RegisterComponents('Additional', [TFileContainer]);
RegisterComponentEditor(TFileContainer, TFileContainerEditor);
end;
{ TFileContainerEditor }
procedure TFileContainerEditor.DoClear;
begin
(Component as TFileContainer).Data := nil;
Designer.Modified;
end;
procedure TFileContainerEditor.DoLoad;
var
FileName: string;
begin
if PromptForFileName(FileName) then begin
(Component as TFileContainer).LoadFromFile(FileName);
Designer.Modified;
end;
end;
procedure TFileContainerEditor.DoSave;
var
FileName: string;
begin
if PromptForFileName(FileName, '', '', '', '', True) then
(Component as TFileContainer).SaveToFile(FileName);
end;
procedure TFileContainerEditor.ExecuteVerb(Index: Integer);
begin
case Index of
0: DoLoad;
1: DoSave;
2: DoClear;
end;
end;
function TFileContainerEditor.GetVerb(Index: Integer): string;
begin
case Index of
0: Result := 'Load';
1: Result := 'Save';
2: Result := 'Clear';
end;
end;
function TFileContainerEditor.GetVerbCount: Integer;
begin
Result := 0;
if Assigned(Component) and (Component is TFileContainer) then begin
Result := 1;
if Length(TFileContainer(Component).Data) > 0 then
Result := 3;
end;
end;
end.