LoginSignup
0
0

More than 5 years have passed since last update.

c++ builder > thisを外部関数に渡す > TForm *formPtr / template <class T> void __fastcall Test_XXX(TObject *Sender) { ((T*)Sender)->Caption = "ABC"; }

Last updated at Posted at 2015-08-06
動作確認
C++ Builder XE4

外部関数からあるFormに対する処理を実装する時、そのForm固有で実装してしまう(Form1->...=)と他のFormに対して処理ができない。

TFormにのみ対応 [this使用]

そのため、thisを引数として渡す方法をとってみる。

.h
class TClassXXX{
public:
  static void Test_XXX(TForm *formPtr);
}

上記を処理したいForm上からコールする。

.cpp
TClassXXX::Test_XXX(this);

TButton, TFormなど色々対応 (mojeldさんより)

templateを使うことで、TFormだけでなく、TButtonなど他のタイプにも対応する場合。

test_xxx.cpp
template <class T>
void __fastcall Test_XXX(TObject *Sender)
{
    ((T*)Sender)->Caption = "ABC";
}
0
0
2

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