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 XE4, 10.2 Tokyo > TMemo | TEdit > TMemoとTEdit共通処理 > TCustomEditを使う

0
Last updated at Posted at 2016-08-23
動作確認
C++ Builder XE4
RAD Studio 10.2 Tokyo Update 2 (追記: 2017/12/28)

TEditで実装してきたソフトをTMemoに変更している。
if (dynamic_cast<TEdit *>(Sender) == NULLのような処理は、当然TMemoではNULLとなる。

このような処理において、TMemoとTEdit両方で使う場合を考えてみた。

型の継承をヘルプで確認した。

  • TMemo
    • TObject > TPersistent > TComponent > TControl > TWinControl > TCustomEdit > TCustomMemo > TMemo
  • TEdit
    • TObject > TPersistent > TComponent > TControl > TWinControl > TCustomEdit > TEdit

上記より、TCustomEdit より親の型に設定すれば共通処理となることが分かる。
TCustomEdit を継承経路に持つ他の型も有効になる点は注意が必要

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::EditMemoClick(TObject *Sender)
{
	if (dynamic_cast<TCustomEdit *>(Sender) == NULL) {
		return;
	}

	TCustomEdit *dstPtr = (TCustomEdit *)Sender;
	dstPtr->Hint = L"Hint text";
	dstPtr->ShowHint = true;
}
//---------------------------------------------------------------------------
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?