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 |
|
|
|
29 |
|
|
#include "ExBitsU.h"
|
30 |
|
|
//---------------------------------------------------------------------------
|
31 |
|
|
#pragma package(smart_init)
|
32 |
|
|
#pragma link "StBits"
|
33 |
|
|
|
34 |
|
|
#pragma resource "*.dfm"
|
35 |
|
|
TForm1 *Form1;
|
36 |
|
|
//---------------------------------------------------------------------------
|
37 |
|
|
__fastcall TForm1::TForm1(TComponent* Owner)
|
38 |
|
|
: TForm(Owner)
|
39 |
|
|
{
|
40 |
|
|
}
|
41 |
|
|
//---------------------------------------------------------------------------
|
42 |
|
|
void TForm1::UpdateButtons(bool BitsOK)
|
43 |
|
|
{
|
44 |
|
|
IsBitSetBtn->Enabled = BitsOK;
|
45 |
|
|
ControlBitBtn->Enabled = BitsOK;
|
46 |
|
|
SetAllBtn->Enabled = BitsOK;
|
47 |
|
|
InvertAllBtn->Enabled = BitsOK;
|
48 |
|
|
ClearAllBtn->Enabled = BitsOK;
|
49 |
|
|
ToggleBitBtn->Enabled = BitsOK;
|
50 |
|
|
SetBitBtn->Enabled = BitsOK;
|
51 |
|
|
ClearBitBtn->Enabled = BitsOK;
|
52 |
|
|
SaveBtn->Enabled = BitsOK;
|
53 |
|
|
};
|
54 |
|
|
//---------------------------------------------------------------------------
|
55 |
|
|
bool TForm1::CheckValue(String S, long &N)
|
56 |
|
|
{
|
57 |
|
|
if (S == "") {
|
58 |
|
|
ShowMessage("No value entered");
|
59 |
|
|
return false;
|
60 |
|
|
};
|
61 |
|
|
|
62 |
|
|
N = StrToInt(S);
|
63 |
|
|
if ((N < 0) || (N > MyBits->Max)) {
|
64 |
|
|
ShowMessage("Number out of range");
|
65 |
|
|
return false;
|
66 |
|
|
};
|
67 |
|
|
return true;
|
68 |
|
|
};
|
69 |
|
|
//---------------------------------------------------------------------------
|
70 |
|
|
String TForm1::GetTFString(long N)
|
71 |
|
|
{
|
72 |
|
|
if (MyBits->BitIsSet(N))
|
73 |
|
|
return "TRUE";
|
74 |
|
|
else
|
75 |
|
|
return "FALSE";
|
76 |
|
|
};
|
77 |
|
|
//---------------------------------------------------------------------------
|
78 |
|
|
void __fastcall TForm1::FormActivate(TObject *Sender)
|
79 |
|
|
{
|
80 |
|
|
IsBitSetValue->Text = "-1";
|
81 |
|
|
ToggleBitValue->Text = "-1";
|
82 |
|
|
SetBitValue->Text = "-1";
|
83 |
|
|
ControlBitValue->Text = "-1";
|
84 |
|
|
ClearBitValue->Text = "-1";
|
85 |
|
|
|
86 |
|
|
Msg1->Lines->Clear();
|
87 |
|
|
Msg1->Lines->Add("BitSet not created");
|
88 |
|
|
}
|
89 |
|
|
//---------------------------------------------------------------------------
|
90 |
|
|
void __fastcall TForm1::FormCreate(TObject *Sender)
|
91 |
|
|
{
|
92 |
|
|
RegisterClassAlias(__classid(TStBits), "TStBits");
|
93 |
|
|
UpdateButtons(false);
|
94 |
|
|
}
|
95 |
|
|
//---------------------------------------------------------------------------
|
96 |
|
|
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
|
97 |
|
|
{
|
98 |
|
|
delete MyBits;
|
99 |
|
|
}
|
100 |
|
|
//---------------------------------------------------------------------------
|
101 |
|
|
void __fastcall TForm1::CreateBtnClick(TObject *Sender)
|
102 |
|
|
{
|
103 |
|
|
long MaxBits;
|
104 |
|
|
|
105 |
|
|
Msg1->Lines->Clear();
|
106 |
|
|
|
107 |
|
|
if (NumElemsValue->Text == "")
|
108 |
|
|
NumElemsValue->Text = "50";
|
109 |
|
|
|
110 |
|
|
MaxBits = StrToInt(NumElemsValue->Text);
|
111 |
|
|
if ((MaxBits < 1) || (MaxBits > 9999)) {
|
112 |
|
|
ShowMessage("Value out of range (1 - 9999)");
|
113 |
|
|
return;
|
114 |
|
|
};
|
115 |
|
|
|
116 |
|
|
Msg1->Lines->Clear();
|
117 |
|
|
|
118 |
|
|
if (!MyBits)
|
119 |
|
|
delete MyBits;
|
120 |
|
|
|
121 |
|
|
UpdateButtons(false);
|
122 |
|
|
MyBits = new TStBits(MaxBits);
|
123 |
|
|
|
124 |
|
|
Label1->Caption = "In entry fields below, enter a value from 0 to "
|
125 |
|
|
+ IntToStr((int)MaxBits);
|
126 |
|
|
Label2->Caption = "Elements in BitSet: " + IntToStr(MyBits->Max+1);
|
127 |
|
|
|
128 |
|
|
IsBitSetValue->Text = "0";
|
129 |
|
|
ToggleBitValue->Text = "0";
|
130 |
|
|
SetBitValue->Text = "0";
|
131 |
|
|
ControlBitValue->Text = "0";
|
132 |
|
|
ClearBitValue->Text = "0";
|
133 |
|
|
|
134 |
|
|
Msg1->Lines->Add("BitSet created");
|
135 |
|
|
Msg1->Lines->Add(IntToStr(MyBits->Count));
|
136 |
|
|
UpdateButtons(true);
|
137 |
|
|
}
|
138 |
|
|
//---------------------------------------------------------------------------
|
139 |
|
|
void __fastcall TForm1::IsBitSetBtnClick(TObject *Sender)
|
140 |
|
|
{
|
141 |
|
|
long BitNum;
|
142 |
|
|
|
143 |
|
|
if (!CheckValue(IsBitSetValue->Text, BitNum))
|
144 |
|
|
return;
|
145 |
|
|
|
146 |
|
|
Msg1->Lines->Clear();
|
147 |
|
|
if (MyBits->BitIsSet(BitNum))
|
148 |
|
|
Msg1->Lines->Add("Bit is set");
|
149 |
|
|
else
|
150 |
|
|
Msg1->Lines->Add( "Bit not set");
|
151 |
|
|
}
|
152 |
|
|
//---------------------------------------------------------------------------
|
153 |
|
|
void __fastcall TForm1::ControlBitBtnClick(TObject *Sender)
|
154 |
|
|
{
|
155 |
|
|
long BitNum;
|
156 |
|
|
String WasStr, NowStr;
|
157 |
|
|
|
158 |
|
|
if (!CheckValue(ControlBitValue->Text, BitNum))
|
159 |
|
|
return;
|
160 |
|
|
|
161 |
|
|
WasStr = GetTFString(BitNum);
|
162 |
|
|
MyBits->ControlBit(BitNum,BitOnCB->Checked);
|
163 |
|
|
NowStr = GetTFString(BitNum);
|
164 |
|
|
|
165 |
|
|
Msg1->Lines->Clear();
|
166 |
|
|
Msg1->Lines->Add("Bit was: " + WasStr);
|
167 |
|
|
Msg1->Lines->Add("Bit is now: " + NowStr);
|
168 |
|
|
}
|
169 |
|
|
//---------------------------------------------------------------------------
|
170 |
|
|
void __fastcall TForm1::SetAllBtnClick(TObject *Sender)
|
171 |
|
|
{
|
172 |
|
|
Msg1->Lines->Clear();
|
173 |
|
|
MyBits->SetBits();
|
174 |
|
|
Msg1->Lines->Add("Bits Set");
|
175 |
|
|
}
|
176 |
|
|
//---------------------------------------------------------------------------
|
177 |
|
|
void __fastcall TForm1::InvertAllBtnClick(TObject *Sender)
|
178 |
|
|
{
|
179 |
|
|
Msg1->Lines->Clear();
|
180 |
|
|
MyBits->InvertBits();
|
181 |
|
|
Msg1->Lines->Add("Bits Inverted");
|
182 |
|
|
}
|
183 |
|
|
//---------------------------------------------------------------------------
|
184 |
|
|
void __fastcall TForm1::ClearAllBtnClick(TObject *Sender)
|
185 |
|
|
{
|
186 |
|
|
Msg1->Lines->Clear();
|
187 |
|
|
MyBits->Clear();
|
188 |
|
|
Msg1->Lines->Add("Bits Cleared");
|
189 |
|
|
}
|
190 |
|
|
//---------------------------------------------------------------------------
|
191 |
|
|
void __fastcall TForm1::ToggleBitBtnClick(TObject *Sender)
|
192 |
|
|
{
|
193 |
|
|
long BitNum;
|
194 |
|
|
String WasStr, NowStr;
|
195 |
|
|
|
196 |
|
|
if (!CheckValue(ToggleBitValue->Text, BitNum))
|
197 |
|
|
return;
|
198 |
|
|
|
199 |
|
|
WasStr = GetTFString(BitNum);
|
200 |
|
|
MyBits->ToggleBit(BitNum);
|
201 |
|
|
NowStr = GetTFString(BitNum);
|
202 |
|
|
|
203 |
|
|
Msg1->Lines->Clear();
|
204 |
|
|
Msg1->Lines->Add("Bit was: " + WasStr);
|
205 |
|
|
Msg1->Lines->Add("Bit is now: " + NowStr);
|
206 |
|
|
}
|
207 |
|
|
//---------------------------------------------------------------------------
|
208 |
|
|
void __fastcall TForm1::SetBitBtnClick(TObject *Sender)
|
209 |
|
|
{
|
210 |
|
|
long BitNum;
|
211 |
|
|
String WasStr, NowStr;
|
212 |
|
|
|
213 |
|
|
if (!CheckValue(SetBitValue->Text, BitNum))
|
214 |
|
|
return;
|
215 |
|
|
|
216 |
|
|
WasStr = GetTFString(BitNum);
|
217 |
|
|
MyBits->SetBit(BitNum);
|
218 |
|
|
NowStr = GetTFString(BitNum);
|
219 |
|
|
|
220 |
|
|
Msg1->Lines->Clear();
|
221 |
|
|
Msg1->Lines->Add("Bit was: " + WasStr);
|
222 |
|
|
Msg1->Lines->Add("Bit is now: " + NowStr);
|
223 |
|
|
}
|
224 |
|
|
//---------------------------------------------------------------------------
|
225 |
|
|
void __fastcall TForm1::ClearBitBtnClick(TObject *Sender)
|
226 |
|
|
{
|
227 |
|
|
long BitNum;
|
228 |
|
|
String WasStr, NowStr;
|
229 |
|
|
|
230 |
|
|
if (!CheckValue(ClearBitValue->Text, BitNum))
|
231 |
|
|
return;
|
232 |
|
|
|
233 |
|
|
WasStr = GetTFString(BitNum);
|
234 |
|
|
MyBits->ClearBit(BitNum);
|
235 |
|
|
NowStr = GetTFString(BitNum);
|
236 |
|
|
|
237 |
|
|
Msg1->Lines->Clear();
|
238 |
|
|
Msg1->Lines->Add("Bit was: " + WasStr);
|
239 |
|
|
Msg1->Lines->Add("Bit is now: " + NowStr);
|
240 |
|
|
}
|
241 |
|
|
//---------------------------------------------------------------------------
|
242 |
|
|
void __fastcall TForm1::LoadBtnClick(TObject *Sender)
|
243 |
|
|
{
|
244 |
|
|
if (OD1->Execute()) {
|
245 |
|
|
if (!MyBits) {
|
246 |
|
|
//create a minimum sized bitset - load will resize it
|
247 |
|
|
MyBits = new TStBits(1);
|
248 |
|
|
if (!MyBits) {
|
249 |
|
|
Msg1->Lines->Add("BitSet Create Failed");
|
250 |
|
|
UpdateButtons(false);
|
251 |
|
|
return;
|
252 |
|
|
};
|
253 |
|
|
};
|
254 |
|
|
|
255 |
|
|
MyBits->Clear();
|
256 |
|
|
MyBits->LoadFromFile(OD1->FileName);
|
257 |
|
|
|
258 |
|
|
Label1->Caption = "In entry fields below, enter a value from 0 to "
|
259 |
|
|
+ IntToStr(MyBits->Max);
|
260 |
|
|
Label2->Caption = "Elements in BitSet: " + IntToStr(MyBits->Max+1);
|
261 |
|
|
|
262 |
|
|
IsBitSetValue->Text = "0";
|
263 |
|
|
ToggleBitValue->Text = "0";
|
264 |
|
|
SetBitValue->Text = "0";
|
265 |
|
|
ControlBitValue->Text = "0";
|
266 |
|
|
ClearBitValue->Text = "0";
|
267 |
|
|
|
268 |
|
|
Msg1->Clear();
|
269 |
|
|
Msg1->Lines->Add("BitSet loaded");
|
270 |
|
|
UpdateButtons(true);
|
271 |
|
|
};
|
272 |
|
|
}
|
273 |
|
|
//---------------------------------------------------------------------------
|
274 |
|
|
void __fastcall TForm1::SaveBtnClick(TObject *Sender)
|
275 |
|
|
{
|
276 |
|
|
if (SD1->Execute()) {
|
277 |
|
|
MyBits->StoreToFile(SD1->FileName);
|
278 |
|
|
Msg1->Clear();
|
279 |
|
|
Msg1->Lines->Add("BitSet saved");
|
280 |
|
|
};
|
281 |
|
|
}
|
282 |
|
|
//---------------------------------------------------------------------------
|
283 |
|
|
|