class UserEditBox : public TEdit
{
private :
AnsiString UserText;
private :
void __fastcall OnMyPaste(TMessage& Message);
protected:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_PASTE, TMessage, OnMyPaste)
END_MESSAGE_MAP(TEdit)
public :
UserEditBox(HWND parent);
AnsiString __fastcall GetText(void);
DECLARE_RESPONSE_TABLE(UserEditBox);
};
UserEditBox::UserEditBox(HWND parent) :TEdit(parent)
{
UserText = "";
}
AnsiString __fastcall UserEditBox::GetText(void)
{
// 這裡會出現 Access violation at address ....in module 的錯誤
UserText = (AnsiString)this->Text;
return UserText ;
}
void __fastcall UserEditBox::OnMyPaste(TMessage& Message)
{
TEdit::Dispatch(&Message);
UserText = this->Text; // 這裡 UserText 有取到 Text 中的值
}