在C ++ Builder中使用Do Begin语句 [英] With Do Begin Statement in C++ Builder
本文介绍了在C ++ Builder中使用Do Begin语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何使用 With Do Begin 语句(类似于Delphi)在C ++ Builder中编写以下代码。
I wanna know how to write the following codes in C++ Builder by using With Do Begin statement similar to Delphi.
我试过与ComboBox->文本.... do ... try
,它不工作。我尝试只是做ComboBox->文本....尝试
,也不工作。
I tried with ComboBox->Text .... do ... try
and it's not working. I tried with just do ComboBox->Text .... try
, also not working.
if (ComboBox->Text.operator==(String("C++ Builder XE7")))
{
try
{
// do something
if ((Form1->Memo1->Lines->Text).Pos("<") !=0)
{
// do something
}
}
catch(Exception &ex)
{
ShowMessage(ex.ToString());
}
if (ComboBox->Text.operator==(String("C++ Builder XE8")))
{
try
{
// do something
if ((Form1->Memo1->Lines->Text).Pos("<") !=0)
{
// do something
}
}
catch(Exception &ex)
{
ShowMessage(ex.ToString());
}
推荐答案
with C / C ++中的
语句。在C ++中最好的做法是使用指针/引用,例如:
There is no equivalent to Delphi's with
statement in C++. The best you can do in C++ is use pointers/references instead, eg:
TComboBox *cb = ComboBox;
TStrings *lines = Form1->Memo1->Lines;
if (cb->Text == "C++ Builder XE7")
{
try
{
// do something
if (lines->Text.Pos("<") != 0)
{
// do something
}
}
catch(const Exception &ex)
{
ShowMessage(const_cast<Exception&>(ex).ToString());
}
}
if (cb->Text == "C++ Builder XE8")
{
try
{
// do something
if (lines->Text.Pos("<") != 0)
{
// do something
}
}
catch(const Exception &ex)
{
ShowMessage(const_cast<Exception&>(ex).ToString());
}
}
这篇关于在C ++ Builder中使用Do Begin语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文