LoginSignup
0
1

More than 5 years have passed since last update.

c++ builder XE4, 10.2 Tokyo > TPanel上のTCheckBox名を取得する

Last updated at Posted at 2016-08-16
動作環境
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2017/12/27)

関連 http://qiita.com/7of9/items/bb16fdc19ac4bbdb5260

TCheckBoxのCheckedプロパティを行列で取得する場合、無関係のTCheckBoxを無視したい。

TPanel上のTCheckBoxかどうかは該当するTCheckBoxの親コンポーネントを調べればよさそう。

Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#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)
{
    for(int idx=0; idx < this->ComponentCount; idx++) {
        TComponent *srcPtr = this->Components[idx];
        TComponent *prntPtr = srcPtr->GetParentComponent();
        if (dynamic_cast<TPanel *>(prntPtr) == NULL) {
            continue;
        }

        OutputDebugString(srcPtr->Name.c_str());
    }
}
//---------------------------------------------------------------------------

qiita.png

結果
デバッグ出力: CheckBox1OnPanel プロセス Project1.exe (3084)
デバッグ出力: CheckBox3OnPanel プロセス Project1.exe (3084)

上記では親コンポーネントがTPanel型の場合にしているが、さらに条件を絞って親コンポーネントのNameプロパティで絞ることで、特定のPanel上のチェックボックスの状態を取得できる。

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