注册 登录
编程论坛 C++ Builder

自訂的 class UserEditBox : public TEdit 出了問題

kuowen 发布于 2008-10-01 16:03, 1283 次点击
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 中的值
}
0 回复
1