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

在class中如何從 function pointer 取得 function name?

尚未結案
panda0800
一般會員


發表:4
回覆:5
積分:1
註冊:2003-03-18

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-08-06 16:54:52 IP:218.165.xxx.xxx 未訂閱
在 class 中的 function 如何從 function pointer 取得 他的 function name? ex: class aa{ int fun1(); int fun2(); } int aa::fun1() { return 1; } int aa::fun2() { void *p= (void*)fun1; <--此行compiler時語法會出錯,請問如何解決? AnsiString str=MethodName(p); //want to got the "fun1" } 發表人 - panda0800 於 2004/08/06 17:31:37
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-08-09 23:04:58 IP:211.76.xxx.xxx 未訂閱
panda0800你好:     MethodName只能用於TObject衍生的class,而且只在用在property的published method。在code中的用法,應該只會傳回一個空字串。     宣告成員函式指標的方法,可以參考下面的範例:  
class A{    public:
    int return5(void){return 5;}
    int return6(void){return 6;}
};    void __fastcall TForm1::Button1Click(TObject *Sender)
{
int (A::*get5)(void);
int (A::*get6)(void);
get5 = A::return5;
get6 = A::return6;    A objectA;
int ia = ((objectA).*(get5))(); //ia = 5
int ib = ((objectA).*(get6))(); //ib = 6
}     
panda0800
一般會員


發表:4
回覆:5
積分:1
註冊:2003-03-18

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-08-22 15:47:17 IP:218.165.xxx.xxx 未訂閱
Dear pwipwi sir, Sorry my net has some trouble recently. Thks for your response. But I want to get the function name string "return5" in code. How can I fill the "return5" in the 回傳的"空字串"? Thks. Best regard, Panda0800
panda0800
一般會員


發表:4
回覆:5
積分:1
註冊:2003-03-18

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-08-22 15:47:30 IP:218.165.xxx.xxx 未訂閱
Dear pwipwi sir, Sorry my net has some trouble recently. Thks for your response. But I want to get the function name string "return5" in code. How can I fill the "return5" in the 回傳的"空字串"? Thks. Best regard, Panda0800
pwipwi
版主


發表:68
回覆:629
積分:349
註冊:2004-04-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-08-22 16:53:32 IP:211.76.xxx.xxx 未訂閱
引言: Dear pwipwi sir, Sorry my net has some trouble recently. Thks for your response. But I want to get the function name string "return5" in code. How can I fill the "return5" in the 回傳的"空字串"? Thks. Best regard, Panda0800
ㄟ...下面的碼有點無厘頭...但,是不是你要的?
#define GetFunctionName(x) #x
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Caption = GetFunctionName(return5);
}
 
panda0800
一般會員


發表:4
回覆:5
積分:1
註冊:2003-03-18

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-09-08 00:20:57 IP:218.165.xxx.xxx 未訂閱
Dear pwipwi, Thanks for your response! But it is'nt my wanted. Thanks for your kind! I giveup this problem solution, and I use a list to record the name and address for searching. Panda0800
系統時間:2024-06-28 2:34:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!