1 |
torben |
2671 |
// ***** BEGIN LICENSE BLOCK *****
|
2 |
|
|
// * Version: MPL 1.1
|
3 |
|
|
// *
|
4 |
|
|
// * The contents of this file are subject to the Mozilla Public License Version
|
5 |
|
|
// * 1.1 (the "License"); you may not use this file except in compliance with
|
6 |
|
|
// * the License. You may obtain a copy of the License at
|
7 |
|
|
// * http://www.mozilla.org/MPL/
|
8 |
|
|
// *
|
9 |
|
|
// * Software distributed under the License is distributed on an "AS IS" basis,
|
10 |
|
|
// * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
11 |
|
|
// * for the specific language governing rights and limitations under the
|
12 |
|
|
// * License.
|
13 |
|
|
// *
|
14 |
|
|
// * The Original Code is TurboPower SysTools
|
15 |
|
|
// *
|
16 |
|
|
// * The Initial Developer of the Original Code is
|
17 |
|
|
// * TurboPower Software
|
18 |
|
|
// *
|
19 |
|
|
// * Portions created by the Initial Developer are Copyright (C) 1996-2002
|
20 |
|
|
// * the Initial Developer. All Rights Reserved.
|
21 |
|
|
// *
|
22 |
|
|
// * Contributor(s):
|
23 |
|
|
// *
|
24 |
|
|
// * ***** END LICENSE BLOCK *****
|
25 |
|
|
//---------------------------------------------------------------------------
|
26 |
|
|
#include <vcl\vcl.h>
|
27 |
|
|
#pragma hdrstop
|
28 |
|
|
#include <stdlib.h>
|
29 |
|
|
#include "ExDictU.h"
|
30 |
|
|
//---------------------------------------------------------------------------
|
31 |
|
|
#pragma package(smart_init)
|
32 |
|
|
#pragma link "StDict"
|
33 |
|
|
|
34 |
|
|
#pragma resource "*.dfm"
|
35 |
|
|
TForm1 *Form1;
|
36 |
|
|
//---------------------------------------------------------------------------
|
37 |
|
|
__fastcall TForm1::TForm1(TComponent* Owner)
|
38 |
|
|
: TForm(Owner)
|
39 |
|
|
{
|
40 |
|
|
}
|
41 |
|
|
//---------------------------------------------------------------------------
|
42 |
|
|
bool __fastcall DDWalker(TStContainer* Container, TStNode* Node, void * OtherData)
|
43 |
|
|
{
|
44 |
|
|
TStDictNode* N = (TStDictNode*) Node;
|
45 |
|
|
ShortString *S = (ShortString*) N->Data;
|
46 |
|
|
Form1->LB1->Items->Add(((TStDictNode*)Node)->Name + " = " + *S);
|
47 |
|
|
return true;
|
48 |
|
|
}
|
49 |
|
|
//---------------------------------------------------------------------------
|
50 |
|
|
void * __fastcall MyLoadData(Classes::TReader* Reader)
|
51 |
|
|
{
|
52 |
|
|
ShortString * S;
|
53 |
|
|
S = new ShortString;
|
54 |
|
|
*S = Reader->ReadString();
|
55 |
|
|
return (void *) S;
|
56 |
|
|
}
|
57 |
|
|
//---------------------------------------------------------------------------
|
58 |
|
|
void __fastcall MyStoreData(Classes::TWriter* Writer, void * Data)
|
59 |
|
|
{
|
60 |
|
|
ShortString *S = (ShortString*) Data;
|
61 |
|
|
Writer->WriteString(*S);
|
62 |
|
|
}
|
63 |
|
|
//---------------------------------------------------------------------------
|
64 |
|
|
void TForm1::FillListBox(void)
|
65 |
|
|
{
|
66 |
|
|
LB1->Clear();
|
67 |
|
|
LB1->Perform(WM_SETREDRAW, 0, 0);
|
68 |
|
|
|
69 |
|
|
MyDD->Iterate(DDWalker, 0);
|
70 |
|
|
|
71 |
|
|
LB1->Perform(WM_SETREDRAW, 1, 0);
|
72 |
|
|
LB1->Update();
|
73 |
|
|
}
|
74 |
|
|
//---------------------------------------------------------------------------
|
75 |
|
|
void TForm1::UpdateButtons(bool DOK)
|
76 |
|
|
{
|
77 |
|
|
ClearBtn->Enabled = DOK;
|
78 |
|
|
AddBtn->Enabled = DOK;
|
79 |
|
|
UpdateBtn->Enabled = DOK;
|
80 |
|
|
ExistsBtn->Enabled = DOK;
|
81 |
|
|
DelBtn->Enabled = DOK;
|
82 |
|
|
SaveBtn->Enabled = DOK;
|
83 |
|
|
LB1->Enabled = DOK;
|
84 |
|
|
}
|
85 |
|
|
//---------------------------------------------------------------------------
|
86 |
|
|
String TForm1::RandomData(void)
|
87 |
|
|
{
|
88 |
|
|
int Len = random(100)+1;
|
89 |
|
|
String S = "";
|
90 |
|
|
for (int I = 1; I <= Len; I++)
|
91 |
|
|
S = S + (char)(random(26) + 'A');
|
92 |
|
|
return S;
|
93 |
|
|
}
|
94 |
|
|
//---------------------------------------------------------------------------
|
95 |
|
|
void __fastcall TForm1::FormCreate(TObject *Sender)
|
96 |
|
|
{
|
97 |
|
|
RegisterClassAlias(__classid(TStDictionary), "TStDictionary");
|
98 |
|
|
RegisterClassAlias(__classid(TStDictNode), "TStDictNode");
|
99 |
|
|
UpdateButtons(false);
|
100 |
|
|
}
|
101 |
|
|
//---------------------------------------------------------------------------
|
102 |
|
|
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
|
103 |
|
|
{
|
104 |
|
|
delete MyDD;
|
105 |
|
|
}
|
106 |
|
|
//---------------------------------------------------------------------------
|
107 |
|
|
void __fastcall TForm1::LB1Click(TObject *Sender)
|
108 |
|
|
{
|
109 |
|
|
String S1, S2;
|
110 |
|
|
int P, Len;
|
111 |
|
|
|
112 |
|
|
S1 = LB1->Items->Strings[LB1->ItemIndex];
|
113 |
|
|
S2 = S1;
|
114 |
|
|
Len = S1.Length();
|
115 |
|
|
P = S1.Pos("=");
|
116 |
|
|
|
117 |
|
|
S1.Delete(P-1, Len-P+2);
|
118 |
|
|
Edit1->Text = S1;
|
119 |
|
|
|
120 |
|
|
S2.Delete(1, P+1);
|
121 |
|
|
Edit2->Text = S2;
|
122 |
|
|
}
|
123 |
|
|
//---------------------------------------------------------------------------
|
124 |
|
|
void __fastcall TForm1::LB1DblClick(TObject *Sender)
|
125 |
|
|
{
|
126 |
|
|
void * P;
|
127 |
|
|
|
128 |
|
|
if (MyDD->Exists(Edit1->Text, P)) {
|
129 |
|
|
MyDD->Delete(Edit1->Text);
|
130 |
|
|
FillListBox();
|
131 |
|
|
}
|
132 |
|
|
LB1->ItemIndex = 0;
|
133 |
|
|
LB1Click(LB1);
|
134 |
|
|
}
|
135 |
|
|
//---------------------------------------------------------------------------
|
136 |
|
|
void __fastcall TForm1::CreateBtnClick(TObject *Sender)
|
137 |
|
|
{
|
138 |
|
|
ShortString *S;
|
139 |
|
|
|
140 |
|
|
randomize;
|
141 |
|
|
if (MyDD)
|
142 |
|
|
delete MyDD;
|
143 |
|
|
|
144 |
|
|
UpdateButtons(false);
|
145 |
|
|
MyDD = new TStDictionary(127);
|
146 |
|
|
MyDD->LoadData = MyLoadData;
|
147 |
|
|
MyDD->StoreData = MyStoreData;
|
148 |
|
|
MyDD->Hash = AnsiELFHashText;
|
149 |
|
|
|
150 |
|
|
for (int I = 1; I <= 100; I++) {
|
151 |
|
|
S = new ShortString;
|
152 |
|
|
*S = RandomData();
|
153 |
|
|
MyDD->Add("Item" + IntToStr(I), S);
|
154 |
|
|
}
|
155 |
|
|
FillListBox();
|
156 |
|
|
UpdateButtons(true);
|
157 |
|
|
}
|
158 |
|
|
//---------------------------------------------------------------------------
|
159 |
|
|
void __fastcall TForm1::ClearBtnClick(TObject *Sender)
|
160 |
|
|
{
|
161 |
|
|
LB1->Clear();
|
162 |
|
|
MyDD->Clear();
|
163 |
|
|
Edit1->Clear();
|
164 |
|
|
Edit2->Clear();
|
165 |
|
|
}
|
166 |
|
|
//---------------------------------------------------------------------------
|
167 |
|
|
void __fastcall TForm1::AddBtnClick(TObject *Sender)
|
168 |
|
|
{
|
169 |
|
|
ShortString Name;
|
170 |
|
|
ShortString *PS;
|
171 |
|
|
|
172 |
|
|
if ((Edit1->Text == "") || (Edit2->Text == "")) {
|
173 |
|
|
ShowMessage("Name and/or data missing");
|
174 |
|
|
return;
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
PS = new ShortString;
|
178 |
|
|
*PS = Edit2->Text;
|
179 |
|
|
Name = Edit1->Text;
|
180 |
|
|
|
181 |
|
|
MyDD->Add(Name, PS);
|
182 |
|
|
|
183 |
|
|
FillListBox();
|
184 |
|
|
}
|
185 |
|
|
//---------------------------------------------------------------------------
|
186 |
|
|
void __fastcall TForm1::UpdateBtnClick(TObject *Sender)
|
187 |
|
|
{
|
188 |
|
|
void * P;
|
189 |
|
|
|
190 |
|
|
if ((Edit1->Text == "") || (Edit2->Text == "")) {
|
191 |
|
|
ShowMessage("Name and/or data missing");
|
192 |
|
|
return;
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
if (MyDD->Exists(Edit1->Text, P)) {
|
196 |
|
|
*((ShortString*)P) = Edit2->Text;
|
197 |
|
|
MyDD->Update(Edit1->Text, P);
|
198 |
|
|
} else {
|
199 |
|
|
ShowMessage(Edit1->Text + " not found");
|
200 |
|
|
return;
|
201 |
|
|
}
|
202 |
|
|
FillListBox();
|
203 |
|
|
}
|
204 |
|
|
//---------------------------------------------------------------------------
|
205 |
|
|
void __fastcall TForm1::ExistsBtnClick(TObject *Sender)
|
206 |
|
|
{
|
207 |
|
|
void *S;
|
208 |
|
|
|
209 |
|
|
if (Edit1->Text == "") {
|
210 |
|
|
ShowMessage("No name entry");
|
211 |
|
|
return;
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
if (MyDD->Exists(Edit1->Text, S)) {
|
215 |
|
|
Edit2->Clear();
|
216 |
|
|
Edit2->Text = *((ShortString*)S);
|
217 |
|
|
Edit2->Update();
|
218 |
|
|
} else
|
219 |
|
|
ShowMessage("No matching entry found");
|
220 |
|
|
}
|
221 |
|
|
//---------------------------------------------------------------------------
|
222 |
|
|
void __fastcall TForm1::DelBtnClick(TObject *Sender)
|
223 |
|
|
{
|
224 |
|
|
void * P;
|
225 |
|
|
|
226 |
|
|
if (Edit1->Text == "") {
|
227 |
|
|
ShowMessage("No name entered");
|
228 |
|
|
return;
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
if (MyDD->Exists(Edit1->Text, P)) {
|
232 |
|
|
MyDD->Delete(Edit1->Text);
|
233 |
|
|
FillListBox();
|
234 |
|
|
} else
|
235 |
|
|
ShowMessage("Entry not found");
|
236 |
|
|
}
|
237 |
|
|
//---------------------------------------------------------------------------
|
238 |
|
|
void __fastcall TForm1::LoadBtnClick(TObject *Sender)
|
239 |
|
|
{
|
240 |
|
|
if (OD1->Execute()) {
|
241 |
|
|
if (!MyDD) {
|
242 |
|
|
UpdateButtons(false);
|
243 |
|
|
MyDD = new TStDictionary(127);
|
244 |
|
|
MyDD->LoadData = MyLoadData;
|
245 |
|
|
MyDD->StoreData = MyStoreData;
|
246 |
|
|
}
|
247 |
|
|
|
248 |
|
|
MyDD->Clear();
|
249 |
|
|
MyDD->LoadFromFile(OD1->FileName);
|
250 |
|
|
|
251 |
|
|
FillListBox();
|
252 |
|
|
UpdateButtons(true);
|
253 |
|
|
}
|
254 |
|
|
}
|
255 |
|
|
//---------------------------------------------------------------------------
|
256 |
|
|
void __fastcall TForm1::SaveBtnClick(TObject *Sender)
|
257 |
|
|
{
|
258 |
|
|
if (SD1->Execute())
|
259 |
|
|
MyDD->StoreToFile(SD1->FileName);
|
260 |
|
|
}
|
261 |
|
|
//--------------------------------------------------------------------------- |