0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C++ Builder 10.2 Tokyo > regex > 特定のパターンを持つ名前のコンポーネントを操作する

0
Last updated at Posted at 2019-05-29
動作環境
RAD Studio 10.2 Tokyo Update 3

概要

  • Combo01_itemNoのようなパターンを持つ名前のコンポーネントを対象とする
  • 正規表現でその対象を特定する

関連

実装

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";
}
//---------------------------------------------------------------------------

実行例

ボタン押下後。

2019-05-29_09h54_27.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?