線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1649
推到 Plurk!
推到 Facebook!

建立回傳函式指標的Property

缺席
tkulimi
一般會員


發表:2
回覆:4
積分:1
註冊:2004-11-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-04-17 02:01:40 IP:218.168.xxx.xxx 訂閱
我想建立回傳函式指標 Array的property
說明如下
1.以下為int Array型態的property

[code cpp]
class cSampleDef
{
private:
int m_nAry[10];
int __fastcall nGetA(const int& nIndex)
{
if(nIndex>=0&&nIndex<10)
return m_nAry[nIndex];
else
return 0;
}
void__fastcall vSetA(const int& nIndex,const int& nValue)
{
if(nIndex>=0&&nIndex<10)
m_nAry[nIndex] = nValue;
}
public:
property int nA[int nIndex]={read = nGetA,write = vSetA};
};
[/code]

2.以下做成函式指標的property

[code cpp]
class cSampleDef
{
private:
void __fastcall (__closure *m_pFun)();
public:
__property void __fastcall (__closure *pCallBack)() = {read = m_pFun, write = m_pFun};
};
[/code]

若是想要做成函式指標 Array的property該如何宣告?

class cSampleDef
{
private:
void __fastcall (__closure *m_pFun[10])();//10個函式指標陣列,該如何實做可以如第一個根據Index回傳或是寫入?
public:
//錯誤宣告__property ?={read = ?,write = ?} ;
};


已經有試出來了,以下是Sample
class cSampleDef
{
private:
void __fastcall (__closure * m_pGrabDoneFun[4])();
void __fastcall (__closure * __fastcall pFunGetGrabDone(const int& nPort))()
{
if(nPort < 0 || nPort > 3)
{
return NULL;
}
return m_pGrabDoneFun[nPort];
}
void __fastcall vSetGrabDoneFun( const int& nPort, void __fastcall (__closure * pFun)())
{
if(nPort < 0 || nPort > 3)
{
return;
}
}
public:
__property void __fastcall (__closure * pGrabDone[int nPort])() = {read = pFunGetGrabDone, write = vSetGrabDoneFun};
};


編輯記錄
tkulimi 重新編輯於 2010-04-17 02:03:04, 註解 無‧
tkulimi 重新編輯於 2010-04-20 01:31:37, 註解 無‧
系統時間:2024-03-29 16:46:24
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!