Home > Back-end >  BCB how to determine whether the statement execution success?
BCB how to determine whether the statement execution success?

Time:10-17

BCB how to determine whether the statement execution success?

For example:
Void __fastcall TForm1: : Button1Click (TObject * Sender)
{
AnsiString AAA="123.567";
Double aaa.
Aaa=aaa. ToDouble ();
. (if "aaa=aaa. ToDouble ();" Perform success) ShowMessage (aaa);
. (if "aaa=aaa. ToDouble ();" Execution is not successful) ShowMessage (" unsuccessful ");
}

Or alternatively:
Void __fastcall TForm1: : Button1Click (TObject * Sender)
{
AnsiString AAA="123.567";
Double aaa.
. (if the AAA is digital) AAA=AAA. ToDouble ();
. (if the AAA is not digital ShowMessage (" to ");
}
Here, my main purpose is to tell the AAA not Numbers of


Background: I am using BCB file in a folder under the batch processing, want to extract data from the file, but some files to extract data failure (similar to the example above), will cause the entire program flow interruption, I want to be able to put these files identified problems, and move to another folder, under the original files the remaining documents to automatic processing,

Not long, thought I learned BCB, but nowhere, and vaguely point, this is abnormal or something?

CodePudding user response:

To view the help, ToDouble failure can throw exceptions, the try and catch statement,

CodePudding user response:

this is an example of exception handling, below is the code window:
 void __fastcall TForm1: : Button1Click (TObject * Sender) 
{
Int I=1, j, the result;
J=0;
Try
{
Result=I/j;//code may have a problem
}
The catch (EDivByZero & amp; E)//only capture EDivByZero type, other types of integrated environment automatic processing
{
//display an error message
ShowMessage (AnsiString (" anomalies captured EDivByZero type "));
}
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void __fastcall TForm1: : Button2Click (TObject * Sender)
{
Int I=1, j, the result;
J=0;
Try
{
Result=I/j;//code may have a problem
}
The catch (Exception & amp; E)//catches Exception type, can capture all the Exception a type of Exception
{
//display an error message
ShowMessage (AnsiString (subtype "Exception" + e.c. with our fabrication: lassName () + "Exception is caught"));
ShowMessage (AnsiString (e.M essage));
}
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void __fastcall TForm1: : Button3Click (TObject * Sender)
{
Int I=1, j, the result;
J=0;
Try
{
Result=I/j;//code may have a problem
}
The catch (int & amp; E)
{
ShowMessage (AnsiString (" exception is captured by the int type "));
}
The catch (EDivByZero & amp; E)
{
ShowMessage (AnsiString (caught EDivByZero type "abnormal"));
}
}

For ideas of the building Lord, is to grasp EConvertError (pointed out that a string or object conversion errors), EInvalidCast (check illegal type conversion) both Exception class, in the VCL library, common Exception handling class is ClassName () method and the Message property, the ClassName () method, the user can know what type of Exception, Message properties can know the details of the abnormal situation, Exception handling class is the parent of the Exception class, all the other Exception handling class is a subclass of he, Exception class c + + Builder help documents under test,
The following is an example of data processing, according to the number of significant digits specifies convert digital, through the use of c + + stream format control, do not know the building Lord for help, window and code is as follows:
 # include" strstream. H 
"# include "fstream. H"
# include "iomanip. H"
Void __fastcall TForm1: : BitBtn1Click (TObject * Sender)
{
Try
{
Int iLength=this - & gt; Edit1 - & gt; The Text. The Length ();
If (iLength<1 | | StrToInt (this - & gt; Edit2 - & gt; The Text) & gt; 12)
return;
Char * StrBuffer=new char [iLength];
Ostrstream ofstr (StrBuffer, iLength);
OfstrThis - & gt; Edit3 - & gt; Text=StrBuffer;
}
The catch (... )
{
MessageBox (Handle, "digital input error", "message", MB_OK);
return;
}
}

The following function, interpretation is Numbers, letters or characters:
 bool __fastcall TForm1: : IsNumeralData (unsigned char c)//determine whether to digital, letter 
{
If (c & gt;='0' & amp; & C & lt;='9')
return TRUE;
If (c & gt;='A' & amp; & C & lt;='Z')
return TRUE;

return FALSE;
}

 bool __fastcall TForm1: : IsGb2312Data (unsigned char unsigned char c1, c2)//determine whether for Chinese 
{
If (((c1 & gt;=0 xa1 & amp; & C1 & lt;=0 xaa) | | (c1 & gt;=0 xb0 & amp; & C1 & lt;=0 xfa))
& & (c2 & gt;=0 xa1 & amp; & C2 & lt;=0 xfe))
{
return TRUE;
}
return FALSE;
}

  • Related