制作OCX的问题,再来这里发一帖,做过的朋友进来帮忙一下
制作OCX的过程中,发现了一大堆问题,最基本的自定义属性问题没有解决,请求帮忙!
通过Type Libray 界面添加自定义属性 User和 Password
头文件中如下
//$$---- Active Form HDR ---- (stActiveFormHdr)//---------------------------------------#ifndef FetionFormImpl1H#define FetionFormImpl1H//---------------------------------------#include <classes.hpp>#include <controls.hpp>#include <stdCtrls.hpp>#include <forms.hpp>#include "FetionFormProj1_TLB.h"#include <AxCtrls.hpp>//---------------------------------------class TFetionForm : public TActiveForm{__published: // IDE-managed Componentsprivate: // User declarationspublic: // User declarations BSTR User; //原来不能访问,所以在这里手工添加了这两个公共变量 BSTR Password; __fastcall TFetionForm(HWND ParentWindow); __fastcall TFetionForm(TComponent* AOwner): TActiveForm(AOwner) {};};//---------------------------------------extern PACKAGE TFetionForm *FetionForm;//---------------------------------------//---------------------------------------class ATL_NO_VTABLE TFetionFormImpl: VCLCONTROL_IMPL(TFetionFormImpl, FetionForm, TFetionForm, IFetionForm, DIID_IFetionFormEvents){ void __fastcall ActivateEvent(TObject *Sender); void __fastcall ClickEvent(TObject *Sender); void __fastcall CreateEvent(TObject *Sender); void __fastcall DblClickEvent(TObject *Sender); void __fastcall DeactivateEvent(TObject *Sender); void __fastcall DestroyEvent(TObject *Sender); void __fastcall KeyPressEvent(TObject *Sender, char &Key); void __fastcall PaintEvent(TObject *Sender);public: void InitializeControl() { m_VclCtl->OnActivate = ActivateEvent; m_VclCtl->OnClick = ClickEvent; m_VclCtl->OnCreate = CreateEvent; m_VclCtl->OnDblClick = DblClickEvent; m_VclCtl->OnDeactivate = DeactivateEvent; m_VclCtl->OnDestroy = DestroyEvent; m_VclCtl->OnKeyPress = KeyPressEvent; m_VclCtl->OnPaint = PaintEvent; } 。。。。。。。。。。。。。。。。。。。。//这里省略了N行 STDMETHOD(set_KeyPreview(VARIANT_BOOL Value)); STDMETHOD(set_PixelsPerInch(long Value)); STDMETHOD(set_PrintScale(TxPrintScale Value)); STDMETHOD(set_Scaled(VARIANT_BOOL Value)); STDMETHOD(set_Visible(VARIANT_BOOL Value)); STDMETHOD(get_User(BSTR* Value)); //从这里开始下面几行是自动生成的 STDMETHOD(set_User(BSTR Value)); STDMETHOD(get_Password(BSTR* Value)); STDMETHOD(set_Password(BSTR Value)); };//---------------------------------------#endif
//$$---- Active Form CPP ---- (stActiveFormSource)//---------------------------------------#include <vcl.h>#pragma hdrstop#include <atl\atlvcl.h>#include "FetionFormImpl1.h"#include "TFetion.h"//---------------------------------------#pragma package(smart_init)#pragma resource "*.dfm"TFetionForm *FetionForm;Fetion ft;//---------------------------------------__fastcall TFetionForm::TFetionForm(HWND ParentWindow) : TActiveForm(ParentWindow){}//---------------------------------------STDMETHODIMP TFetionFormImpl::_set_Font(IFontDisp** Value){ try { const DISPID dispid = -512; if (FireOnRequestEdit(dispid) == S_FALSE) return S_FALSE; SetVclCtlProp(m_VclCtl->Font, Value); FireOnChanged(dispid); } catch(Exception &e) { return Error(e.Message.c_str(), IID_IFetionForm); } return S_OK;}; 。。。。。。。。。。。。。。。。。。。。//这里省略了N行STDMETHODIMP TFetionFormImpl::get_User(BSTR* Value){ try { *Value = WideString(m_VclCtl->User).Copy(); //这里是我手式添加的 } catch(Exception &e) { return Error(e.Message.c_str(), IID_IFetionForm); } return S_OK;};STDMETHODIMP TFetionFormImpl::set_User(BSTR Value){ try { m_VclCtl->User = Value;//这里是我手式添加的 } catch(Exception &e) { return Error(e.Message.c_str(), IID_IFetionForm); } return S_OK;};STDMETHODIMP TFetionFormImpl::get_Password(BSTR* Value){ try { *Value = WideString(m_VclCtl->Password).Copy();//这里是我手式添加的 } catch(Exception &e) { return Error(e.Message.c_str(), IID_IFetionForm); } return S_OK;};STDMETHODIMP TFetionFormImpl::set_Password(BSTR Value){ try { m_VclCtl->Password= Value;//这里是我手式添加的 } catch(Exception &e) { return Error(e.Message.c_str(), IID_IFetionForm); } return S_OK;};
void __fastcall TForm1::Button1Click(TObject *Sender){ ft->User="test"; ShowMessage(ft->User ); //这时显示 "test"是对的 ft->Password="123456"; ShowMessage(ft->User ); //这里显示“123456”,莫名的错误,怎么Passowrd得到了User的值?????? ShowMessage(ft->Password ); //这里显示也是“123456”,晕呀,问题出在哪呢????}