/[projects]/dao/DelphiScanner/Components/tpsystools_4.04/examples/CBuilder/Ex2DArrU.cpp
ViewVC logotype

Annotation of /dao/DelphiScanner/Components/tpsystools_4.04/examples/CBuilder/Ex2DArrU.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2671 - (hide annotations) (download)
Tue Aug 25 18:15:15 2015 UTC (8 years, 9 months ago) by torben
File size: 8870 byte(s)
Added tpsystools component
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 <stdlib.h>
30     #include "Ex2DArrU.h"
31     //---------------------------------------------------------------------------
32     #pragma package(smart_init)
33     #pragma link "StLArr"
34     #pragma link "StUtils"
35    
36     #pragma resource "*.dfm"
37    
38    
39     TForm1 *Form1;
40     //---------------------------------------------------------------------------
41     __fastcall TForm1::TForm1(TComponent* Owner)
42     : TForm(Owner)
43     {
44     }
45     //---------------------------------------------------------------------------
46     int __fastcall MyArraySort(const void* E1, const void* E2)
47     {
48     return *(long*)E1 - *(long*)E2;
49     }
50     //---------------------------------------------------------------------------
51    
52     void __fastcall TForm1::FormCreate(TObject *Sender)
53     {
54     //RegisterClass should be used, but it is not there in C++Builder 1.0
55     RegisterClassAlias(__classid(TStLMatrix), "TStLMatrix");
56     UpdateButtons(false);
57     }
58     //---------------------------------------------------------------------------
59     void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
60     {
61     delete MyLMatrix;
62     }
63     //---------------------------------------------------------------------------
64     void TForm1::UpdateButtons(bool AOK)
65     {
66     ClearBtn->Enabled = AOK;
67     FillBtn->Enabled = AOK;
68     PutBtn->Enabled = AOK;
69     PutRowBtn->Enabled = AOK;
70     GetBtn->Enabled = AOK;
71     GetRowBtn->Enabled = AOK;
72     SortBtn->Enabled = AOK;
73     SaveBtn->Enabled = AOK;
74     }
75     //---------------------------------------------------------------------------
76     void TForm1::SetBusy(bool B)
77     {
78     if (B)
79     Screen->Cursor = crHourGlass;
80     else
81     Screen->Cursor = crDefault;
82     }
83     //---------------------------------------------------------------------------
84     void TForm1::FillListBox()
85     {
86     long Value;
87    
88     SetBusy(true);
89     ArrayLB->Clear();
90     ArrayLB->Perform(WM_SETREDRAW, 0, 0);
91    
92     for (Cardinal Row = 0; Row < MyLMatrix->Rows; Row++) {
93     for (Cardinal Col = 0; Col < MyLMatrix->Cols; Col++) {
94     MyLMatrix->Get(Row, Col, &Value);
95     ArrayLB->Items->Add(IntToStr(Row) + "," +
96     IntToStr(Col) + " = " + IntToStr((int)Value));
97     };
98     };
99    
100     ArrayLB->Perform(WM_SETREDRAW,1,0);
101     ArrayLB->Update();
102     SetBusy(false);
103     }
104     //---------------------------------------------------------------------------
105     void __fastcall TForm1::CreateBtnClick(TObject *Sender)
106     {
107     long Value;
108    
109     ArrayLB->Clear();
110    
111     if (MyLMatrix)
112     delete MyLMatrix;
113    
114     UpdateButtons(false);
115     MyLMatrix = new TStLMatrix(MAXROWS, MAXCOLS, sizeof(long));
116     MyLMatrix->ElementsStorable = true;
117    
118     SetBusy(true);
119     for (Cardinal Row = 0; Row < MAXROWS; Row++) {
120     for (Cardinal Col = 0; Col < MAXCOLS; Col++) {
121     Value = floor(random(10000));
122     MyLMatrix->Put(Row, Col, &Value);
123     };
124     };
125     SetBusy(false);
126    
127     FillListBox();
128     UpdateButtons(true);
129    
130     LMRow->Text = "0";
131     LMCol->Text = "0";
132     MyLMatrix->Get(0, 0, &Value);
133     LMValue->Text = IntToStr((int)Value);
134     }
135     //---------------------------------------------------------------------------
136     void __fastcall TForm1::ClearBtnClick(TObject *Sender)
137     {
138     long Value;
139    
140     MyLMatrix->Clear();
141     ArrayLB->Clear();
142    
143     LMRow->Text = "0";
144     LMCol->Text = "0";
145     MyLMatrix->Get(0, 0, &Value);
146     LMValue->Text = IntToStr((int)Value);
147     }
148     //---------------------------------------------------------------------------
149     void __fastcall TForm1::FillBtnClick(TObject *Sender)
150     {
151     long Row, Col, Value;
152    
153     if (LMValue->Text == "") {
154     ShowMessage("No value entered");
155     return;
156     };
157    
158     Value = StrToInt(LMValue->Text);
159     MyLMatrix->Fill(&Value);
160    
161     FillListBox();
162    
163     Row = 0;
164     Col = 0;
165     LMRow->Text = IntToStr((int)Row);
166     LMCol->Text = IntToStr((int)Col);
167    
168     MyLMatrix->Get(Row, Col, &Value);
169     LMValue->Text = IntToStr((int)Value);
170    
171     SetBusy(false);
172     }
173     //---------------------------------------------------------------------------
174     void __fastcall TForm1::PutBtnClick(TObject *Sender)
175     {
176     long LBE, Row, Col, Value;
177    
178     if (LMValue->Text == "") {
179     ShowMessage("No value entered");
180     return;
181     };
182    
183     if (LMRow->Text == "")
184     LMRow->Text = "0";
185     if (LMCol->Text == "")
186     LMCol->Text = "0";
187    
188     Value = StrToInt(LMValue->Text);
189     Row = StrToInt(LMRow->Text);
190     Col = StrToInt(LMCol->Text);
191     MyLMatrix->Put(Row, Col, &Value);
192    
193     LBE = (Row * MAXROWS) + Col;
194     ArrayLB->Items->Strings[LBE] = IntToStr((int)Row) + "," +
195     IntToStr((int)Col) + " = " + IntToStr((int)Value);
196    
197     Row = StrToInt(LMRow->Text);
198     Col = StrToInt(LMCol->Text);
199     MyLMatrix->Get(Row, Col, &Value);
200     LMValue->Text = IntToStr((int)Value);
201     }
202     //---------------------------------------------------------------------------
203     void __fastcall TForm1::PutRowBtnClick(TObject *Sender)
204     {
205     long Row, Col, Value;
206    
207     if (LMValue->Text == "") {
208     ShowMessage("No value entered");
209     return;
210     };
211    
212     if (LMRow->Text == "")
213     LMRow->Text = "0";
214    
215     Value = StrToInt(LMValue->Text);
216     Row = StrToInt(LMRow->Text);
217    
218     FillStruct(&LIArray, MAXCOLS, &Value, sizeof(Value));
219    
220     MyLMatrix->PutRow(Row, &LIArray);
221     FillListBox();
222    
223     Row = StrToInt(LMRow->Text);
224     Col = 0;
225     MyLMatrix->Get(Row, Col, &Value);
226    
227     LMValue->Text = IntToStr((int)Value);
228     LMCol->Text = "0";
229     }
230     //---------------------------------------------------------------------------
231     void __fastcall TForm1::GetBtnClick(TObject *Sender)
232     {
233     long LBE, Row, Col, Value;
234    
235     if (LMValue->Text == "") {
236     ShowMessage("No value entered");
237     return;
238     };
239    
240     if (LMRow->Text == "")
241     LMRow->Text = "0";
242     if (LMCol->Text == "")
243     LMCol->Text = "0";
244    
245     Value = StrToInt(LMValue->Text);
246     Row = StrToInt(LMRow->Text);
247     Col = StrToInt(LMCol->Text);
248     MyLMatrix->Get(Row, Col, &Value);
249    
250     LMRow->Text = IntToStr((int)Row);
251     LMCol->Text = IntToStr((int)Col);
252     LMValue->Text = IntToStr((int)Value);
253    
254     LBE = (Row * MAXCOLS) + Col;
255     ArrayLB->ItemIndex = LBE;
256     }
257     //---------------------------------------------------------------------------
258     void __fastcall TForm1::GetRowBtnClick(TObject *Sender)
259     {
260     long LIV;
261    
262     if (LMRow->Text == "")
263     LMRow->Text = "0";
264    
265     LIV = 0;
266     FillStruct(&LIArray, MAXCOLS, &LIV, sizeof(LIV));
267     MyLMatrix->GetRow(0, &LIArray);
268    
269     ArrayLB->Clear();
270     ArrayLB->Perform(WM_SETREDRAW,0,0);
271    
272     for (long Step = 0; Step < MAXCOLS; Step++)
273     ArrayLB->Items->Add("Col" + IntToStr((int)Step) + ": " + IntToStr((int)LIArray[Step]));
274    
275     ArrayLB->Perform(WM_SETREDRAW, 1, 0);
276     ArrayLB->Update();
277     }
278     //---------------------------------------------------------------------------
279     void __fastcall TForm1::SortBtnClick(TObject *Sender)
280     {
281     MyLMatrix->SortRows(0, MyArraySort);
282     FillListBox();
283     }
284     //---------------------------------------------------------------------------
285     void __fastcall TForm1::LoadBtnClick(TObject *Sender)
286     {
287     if (OD1->Execute()) {
288     if (!MyLMatrix) {
289     UpdateButtons(false);
290     MyLMatrix = new TStLMatrix(MAXROWS, MAXCOLS, sizeof(long));
291     MyLMatrix->ElementsStorable = true;
292     };
293     MyLMatrix->LoadFromFile(OD1->FileName);
294     FillListBox();
295     UpdateButtons(true);
296     };
297     }
298     //---------------------------------------------------------------------------
299     void __fastcall TForm1::SaveBtnClick(TObject *Sender)
300     {
301     if (SD1->Execute())
302     MyLMatrix->StoreToFile(SD1->FileName);
303     }
304     //---------------------------------------------------------------------------
305     void __fastcall TForm1::ArrayLBDblClick(TObject *Sender)
306     {
307     long Row, Col, I, Value;
308    
309     I = ArrayLB->ItemIndex;
310     Row = I / MAXCOLS;
311     Col = I % MAXCOLS;
312    
313     MyLMatrix->Get(Row, Col, &Value);
314     LMRow->Text = IntToStr((int)Row);
315     LMCol->Text = IntToStr((int)Col);
316     LMValue->Text = IntToStr((int)Value);
317     }
318     //---------------------------------------------------------------------------

  ViewVC Help
Powered by ViewVC 1.1.20