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

Annotation of /dao/DelphiScanner/Components/tpsystools_4.04/examples/CBuilder/ExDQueU.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: 6211 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 "ExDQueU.h"
30     //---------------------------------------------------------------------------
31     #pragma package(smart_init)
32     #pragma link "StDQue"
33    
34     #pragma resource "*.dfm"
35     TForm1 *Form1;
36     //---------------------------------------------------------------------------
37     __fastcall TForm1::TForm1(TComponent* Owner)
38     : TForm(Owner)
39     {
40     }
41     //---------------------------------------------------------------------------
42     void __fastcall MyDelNodeData(void * Data)
43     {
44     delete (String*)Data;
45     }
46     //---------------------------------------------------------------------------
47     void * __fastcall MyLoadData(Classes::TReader* Reader)
48     {
49     String *S;
50     S = new String;
51     *S = Reader->ReadString();
52     return S;
53     }
54     //---------------------------------------------------------------------------
55     void __fastcall MyStoreData(Classes::TWriter* Writer, void * Data)
56     {
57     Writer->WriteString( (*(String*)Data) );
58     }
59     //---------------------------------------------------------------------------
60     void __fastcall TForm1::FormCreate(TObject *Sender)
61     {
62     RegisterClassAlias(__classid(TStDQue), "TStDQue");
63     RegisterClassAlias(__classid(TStListNode), "TStListNode");
64     UpdateButtons(false);
65     }
66     //---------------------------------------------------------------------------
67     void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
68     {
69     delete MyDQue;
70     }
71     //---------------------------------------------------------------------------
72     void __fastcall TForm1::CreateBtnClick(TObject *Sender)
73     {
74     String *S;
75    
76     if (MyDQue)
77     delete MyDQue;
78    
79     UpdateButtons(false);
80     MyDQue = new TStDQue(__classid(TStListNode));
81    
82     MyDQue->DisposeData = MyDelNodeData;
83     MyDQue->LoadData = MyLoadData;
84     MyDQue->StoreData = MyStoreData;
85    
86     for (int I = 1; I <= 100; I++) {
87     S = new String;
88     *S = "Item" + IntToStr(I);
89     MyDQue->Append(S);
90     }
91     FillListBox();
92     UpdateButtons(true);
93     }
94     //---------------------------------------------------------------------------
95     void __fastcall TForm1::ClearBtnClick(TObject *Sender)
96     {
97     MyDQue->Clear();
98     Edit1->Text = "";
99     FillListBox();
100     UpdateButtons(false);
101     }
102     //---------------------------------------------------------------------------
103     void __fastcall TForm1::PushHeadBtnClick(TObject *Sender)
104     {
105     String *NewString;
106    
107     if (Edit1->Text == "") {
108     ShowMessage("No value entered");
109     return;
110     }
111    
112     NewString = new String;
113     *NewString = Edit1->Text;
114     MyDQue->PushHead(NewString);
115     FillListBox();
116     }
117     //---------------------------------------------------------------------------
118     void __fastcall TForm1::PopHeadBtnClick(TObject *Sender)
119     {
120     MyDQue->PopHead();
121     FillListBox();
122     }
123     //---------------------------------------------------------------------------
124     void __fastcall TForm1::PushTailBtnClick(TObject *Sender)
125     {
126     String *NewString;
127    
128     if (Edit1->Text == "") {
129     ShowMessage("No value entered");
130     return;
131     }
132    
133     NewString = new String;
134     *NewString = Edit1->Text;
135     MyDQue->PushTail(NewString);
136     FillListBox();
137     }
138     //---------------------------------------------------------------------------
139     void __fastcall TForm1::PopTailBtnClick(TObject *Sender)
140     {
141     MyDQue->PopTail();
142     FillListBox();
143     }
144     //---------------------------------------------------------------------------
145     void __fastcall TForm1::HeadBtnClick(TObject *Sender)
146     {
147     void *Data;
148    
149     MyDQue->PeekHead(Data);
150     Edit1->Text = *((String*)Data);
151     }
152     //---------------------------------------------------------------------------
153     void __fastcall TForm1::TailBtnClick(TObject *Sender)
154     {
155     void *Data;
156    
157     MyDQue->PeekTail(Data);
158     Edit1->Text = *((String*)Data);
159     }
160     //---------------------------------------------------------------------------
161     void __fastcall TForm1::LoadBtnClick(TObject *Sender)
162     {
163     if (OD1->Execute()) {
164     if (!MyDQue) {
165     UpdateButtons(false);
166     MyDQue = new TStDQue(__classid(TStListNode));
167     MyDQue->DisposeData = MyDelNodeData;
168     MyDQue->LoadData = MyLoadData;
169     MyDQue->StoreData = MyStoreData;
170     }
171     MyDQue->LoadFromFile(OD1->FileName);
172     FillListBox();
173     UpdateButtons(true);
174     }
175     }
176     //---------------------------------------------------------------------------
177     void __fastcall TForm1::SaveBtnClick(TObject *Sender)
178     {
179     if (SD1->Execute())
180     MyDQue->StoreToFile(SD1->FileName);
181     }
182     //---------------------------------------------------------------------------
183     void TForm1::FillListBox(void)
184     {
185     TStListNode *PN;
186    
187     LB1->Clear();
188     LB1->Perform(WM_SETREDRAW, 0, 0);
189     PN = MyDQue->Head;
190     while (PN) {
191     LB1->Items->Add(*((String*)(PN->Data)));
192     PN = MyDQue->Next(PN);
193     }
194     LB1->Perform(WM_SETREDRAW, 1, 0);
195     LB1->Update();
196     }
197     //---------------------------------------------------------------------------
198     void TForm1::UpdateButtons(bool QueOK)
199     {
200     ClearBtn->Enabled = QueOK;
201     PushHeadBtn->Enabled = QueOK;
202     PopHeadBtn->Enabled = QueOK;
203     PushTailBtn->Enabled = QueOK;
204     PopTailBtn->Enabled = QueOK;
205     HeadBtn->Enabled = QueOK;
206     TailBtn->Enabled = QueOK;
207     SaveBtn->Enabled = QueOK;
208     }
209     //---------------------------------------------------------------------------

  ViewVC Help
Powered by ViewVC 1.1.20