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
|
unit SWKey;
interface
uses
SwordAPI, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TSWKey = class(TComponent)
private
protected
hswkey: integer;
KeyType: AnsiString;
procedure Loaded; override;
function GetText: AnsiString; virtual;
procedure SetText(itext: AnsiString); virtual;
function GetPersist: Boolean; virtual;
procedure SetPersist(ival: Boolean); virtual;
function GetSWHandle: integer; virtual;
procedure SetSWHandle(ihandle: integer); virtual;
public
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
procedure Initialize; virtual;
property Text: AnsiString read GetText write SetText;
property Persist: Boolean read GetPersist write SetPersist;
function Error: integer; virtual;
property SWHandle: integer read GetSWHandle write SetSWHandle;
procedure Inc; virtual;
procedure Dec; virtual;
published
end;
procedure Register;
implementation
constructor TSWKey.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
KeyType := 'StrKey';
hswkey := 0;
end;
destructor TSWKey.Destroy;
begin
if not (csDesigning in ComponentState) then
begin
if (hswkey <> 0) then
begin
DeleteKey(hswkey);
hswkey := 0;
end;
end;
inherited Destroy;
end;
procedure TSWKey.Loaded;
begin
inherited Loaded;
if not (csDesigning in ComponentState) then
begin
if (hswkey = 0) then
Initialize;
end;
end;
procedure TSWKey.Initialize;
begin
if (hswkey <> 0) then
DeleteKey(hswkey);
hswkey := NewKey(PChar(KeyType));
Persist := true;
end;
function TSWKey.Error: integer;
begin
Error := KeyError(hswkey);
end;
function TSWKey.GetText: AnsiString;
var
s1: AnsiString;
begin
SetLength(s1, 1024);
KeyGetText(hswkey, PChar(s1), Length(s1));
s1 := Trim(s1);
GetText := s1;
end;
procedure TSWKey.SetText(itext: AnsiString);
begin
KeySetText(hswkey, PChar(itext));
end;
function TSWKey.GetSWHandle: integer;
begin
GetSWHandle := hswkey;
end;
procedure TSWKey.SetSWHandle(ihandle: integer);
begin
hswkey := ihandle;
end;
function TSWKey.GetPersist: Boolean;
begin
GetPersist := Boolean(KeyGetPersist(hswkey));
end;
procedure TSWKey.SetPersist(ival: Boolean);
begin
KeySetPersist(hswkey, integer(ival));
end;
procedure TSWKey.Inc;
begin
KeyInc(hswkey);
end;
procedure TSWKey.Dec;
begin
KeyDec(hswkey);
end;
procedure Register;
begin
RegisterComponents('Data Access', [TSWKey]);
end;
end.
|