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

Contents of /dao/DelphiScanner/Components/tpsystools_4.04/examples/CBuilder/exregeu1.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2671 - (show annotations) (download)
Tue Aug 25 18:15:15 2015 UTC (8 years, 9 months ago) by torben
File size: 5910 byte(s)
Added tpsystools component
1 // ***** 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 #include <vcl\forms.hpp>
28 #pragma hdrstop
29
30 #include "exregeu1.h"
31 #include "exregeu2.h"
32 #include "ststrs.hpp"
33 //---------------------------------------------------------------------------
34 #pragma link "StRegEx"
35 #pragma link "cgauges"
36 #pragma link "StBase"
37 #pragma resource "*.dfm"
38 TForm1 *Form1;
39 //---------------------------------------------------------------------------
40 __fastcall TForm1::TForm1(TComponent* Owner)
41 : TForm(Owner)
42 {
43 }
44 //---------------------------------------------------------------------------
45 void __fastcall TForm1::bntSelAvoidClick(TObject *Sender)
46 {
47 TForm2* Form2 = new TForm2(this);
48
49 Form2->Memo1->Clear();
50 Form2->Memo1->Lines->Assign(StRegEx1->SelAvoidPattern);
51 if (Form2->ShowModal() == mrOk) {
52 StRegEx1->SelAvoidPattern->Clear();
53 StRegEx1->SelAvoidPattern->Assign(Form2->Memo1->Lines);
54 }
55
56 delete Form2;
57 }
58 //---------------------------------------------------------------------------
59 void __fastcall TForm1::btnMatchClick(TObject *Sender)
60 {
61 TForm2* Form2 = new TForm2(this);
62
63 Form2->Memo1->Clear();
64 Form2->Memo1->Lines->Assign(StRegEx1->MatchPattern);
65 if (Form2->ShowModal() == mrOk) {
66 StRegEx1->MatchPattern->Clear();
67 StRegEx1->MatchPattern->Assign(Form2->Memo1->Lines);
68 }
69
70 delete Form2;
71 }
72 //---------------------------------------------------------------------------
73 void __fastcall TForm1::btnReplaceClick(TObject *Sender)
74 {
75 TForm2* Form2 = new TForm2(this);
76
77 Form2->Memo1->Clear();
78 Form2->Memo1->Lines->Assign(StRegEx1->ReplacePattern);
79 if (Form2->ShowModal() == mrOk) {
80 StRegEx1->ReplacePattern->Clear();
81 StRegEx1->ReplacePattern->Assign(Form2->Memo1->Lines);
82 }
83
84 delete Form2;
85 }
86 //---------------------------------------------------------------------------
87 void __fastcall TForm1::Button1Click(TObject *Sender)
88 {
89 ACount = 0;
90
91 if (cbxModOnly->Checked)
92 StRegEx1->OutputOptions = StRegEx1->OutputOptions << ooModified;
93 else
94 StRegEx1->OutputOptions = StRegEx1->OutputOptions >> ooModified;
95
96 if (cbxCountOnly->Checked)
97 StRegEx1->OutputOptions = StRegEx1->OutputOptions << ooCountOnly;
98 else
99 StRegEx1->OutputOptions = StRegEx1->OutputOptions >> ooCountOnly;
100
101 if ((Trim(edtSourceFile->Text) == "") ||
102 (Trim(edtDestFile->Text) == "") &&
103 (!StRegEx1->OutputOptions.Contains(ooCountOnly))) {
104 ShowMessage("Source and/or Destination file cannot be blank");
105 return;
106 }
107
108 if (!FileExists(Trim(edtSourceFile->Text))) {
109 ShowMessage("Source file not found");
110 return;
111 }
112
113 if ((StRegEx1->SelAvoidPattern->Count == 0) &&
114 (StRegEx1->MatchPattern->Count == 0)) {
115 ShowMessage("You must specify a SelAvoid or Match Pattern");
116 return;
117 }
118
119 StRegEx1->IgnoreCase = cbIgnoreCase->Checked;
120 StRegEx1->Avoid = !cbSelect->Checked;
121 StRegEx1->LineNumbers = cbLineNumbers->Checked;
122 StRegEx1->InputFile = TrimS(edtSourceFile->Text);
123 StRegEx1->OutputFile = edtDestFile->Text;
124
125 lblSelAvoid->Caption = "Sel/Avoid: 0";
126 lblMatch->Caption = "Match: 0";
127 lblReplace->Caption = "ReplaceL 0";
128 lblLPS->Caption = "Lines/Sec: 0";
129
130 Screen->Cursor = crHourGlass;
131 StRegEx1->Execute();
132 Screen->Cursor = crDefault;
133
134
135 Memo1->Clear();
136 if (!StRegEx1->OutputOptions.Contains(ooCountOnly))
137 Memo1->Lines->LoadFromFile(edtDestFile->Text);
138
139 lblSelAvoid->Caption = "Sel/Avoid: " + IntToStr(StRegEx1->LinesSelected);
140 lblMatch->Caption = "Match: " + IntToStr(StRegEx1->LinesMatched);
141 lblReplace->Caption = "Replace: " + IntToStr(StRegEx1->LinesReplaced);
142 lblLPS->Caption = "Lines/Sec: " + IntToStr(StRegEx1->LinesPerSecond);
143
144 }
145 //---------------------------------------------------------------------------
146 void __fastcall TForm1::SelectFile(TObject *Sender)
147 {
148 if (Sender == sbSource) {
149 OpenDialog1->Title = "Source File";
150 OpenDialog1->Options = OpenDialog1->Options << ofFileMustExist;
151 if (OpenDialog1->Execute())
152 edtSourceFile->Text = OpenDialog1->FileName;
153 }
154 else {
155 OpenDialog1->Title = "Destination File";
156 OpenDialog1->Options = OpenDialog1->Options >> ofFileMustExist;
157 if (OpenDialog1->Execute())
158 edtDestFile->Text = OpenDialog1->FileName;
159 }
160 }
161 //---------------------------------------------------------------------------
162 void __fastcall TForm1::StRegEx1Match(TObject *Sender,
163 TMatchPosition &REPosition)
164 {
165 ACount++;
166 Caption = IntToStr(REPosition.LineNum);
167 Application->ProcessMessages();
168 }
169 //---------------------------------------------------------------------------
170 void __fastcall TForm1::StRegEx1Progress(TObject *Sender, WORD Percent)
171 {
172 if (((Percent % 2) == 0) && (Gauge1->Progress != Percent)) {
173 Gauge1->Progress = Percent;
174 }
175 }
176 //---------------------------------------------------------------------------
177

  ViewVC Help
Powered by ViewVC 1.1.20