動作環境
RAD Studio 10.2 Tokyo Update 3
概要
-
Combo01_itemNoのようなパターンを持つ名前のコンポーネントを対象とする - 正規表現でその対象を特定する
関連
-
https://www.debuggex.com/
- 正規表現の確認用
- 今回のパターンの確認
- c++ builder XE4, 10.2 Tokyo > 正規表現 > 特定の1文字だけ違うものを許容する
- ズンドコキヨシ with 正規表現 > (((Zun){1,4})Doko)Kiyoshi | debuggex.comでの正規表現表示
- C++ Builder 10.2 Tokyo > FindComponent()した結果をTEdit *に入れる場合 > dynamic_castと(TEdit *)キャストの違い
実装
Unit1.cpp
//---------------------------------------------------------------------------
# include <vcl.h>
# pragma hdrstop
# include <System.RegularExpressions.hpp>
# include "Unit1.h"
//---------------------------------------------------------------------------
# pragma package(smart_init)
# pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String aptrn = "Combo.*_itemNo";
for(int idx=0; idx<this->ComponentCount; idx++) {
TComponent *aptr = this->Components[idx];
TComboBox *cmbPtr = dynamic_cast<TComboBox*>(aptr);
if (cmbPtr == NULL) {
continue;
}
if (TRegEx::IsMatch(cmbPtr->Name, aptrn) == false) {
continue;
}
cmbPtr->ItemIndex = 1;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
Combo01_itemNo->Items->CommaText = L"pi,napier,Avogadro";
Combi02_itemNo->Items->CommaText = L"pi,napier,Avogadro";
Combo03_itemNo->Items->CommaText = L"pi,napier,Avogadro";
}
//---------------------------------------------------------------------------
実行例
ボタン押下後。
