0
1

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 XE4, 10.2 Tokyo > コンポーネントのタイプ?(TLabelなど)を取得する > srcPtr->ClassName() / bool isTLabel = (dynamic_cast<TLabel *>(lblPtr) != NULL);

Last updated at Posted at 2015-10-11
動作確認
C++ Builder XE4
Rad Studio 10.2 Tokyo Update 2 (追記: 2017/12/27)

##try1

コンポーネントがTCheckBoxかどうかの確認にはClassName()を使う。

static bool isTCheckBox(TControl *srcPtr)
{
	if (srcPtr->ClassName() == L"TCheckBox") {
		return true;
	}
	return false;
}

ヘルプのVcl.Controls.TControl のメソッドを参考にした。


##try2 [SO](http://stackoverflow.com/questions/33060775/how-to-know-the-control-is-tlabel/33068111#33068111)にて教えていただいた方法。 以下を使う。
if (dynamic_cast<TLabel*>(ParentControl->Controls[i]) != NULL)

実装してみた。

void __fastcall TForm1::Button1Click(TObject *Sender)
{
	TControl *lblPtr = (TControl *)Label1;

	bool isTLabel = (dynamic_cast<TLabel *>(lblPtr) != NULL);
	bool isTComboBox = (dynamic_cast<TComboBox *>(lblPtr) != NULL);

	Memo1->Lines->Add(BoolToStr(isTLabel));
	Memo1->Lines->Add(BoolToStr(isTComboBox));
}
結果
-1
0
0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?