全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1362
推到 Plurk!
推到 Facebook!

C++ 轉 Delphi

答題得分者是:ccchen
nj825
一般會員


發表:3
回覆:7
積分:2
註冊:2002-04-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-08-18 01:10:10 IP:61.70.xxx.xxx 未訂閱
請教各位前輩:    DWORD ResultProc(int hLine, const pRec pResult, DWORD dwUserData) {    char *pKey = NULL;    int  nLen = 0;            pKeyWord = new char[nLen];         GetValue (pResult->pszResult, pKey, &nLen);            cout<<"The Result is: "<
pszResult<Key<nCon<fnNotify = &ResultProc;     以上該如何轉為 Delphi 呢? 尤其是最後一段, 有個 & 的地方, 是什麼意思呢?    多謝各位前面的解答~~~     
        
ccchen
版主


發表:61
回覆:940
積分:1394
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-08-18 10:01:21 IP:203.217.xxx.xxx 未訂閱
問題中有太多變數, 程序未在你所顯示之資料中,你要改寫的部分包含那些範圍均為說明, 因此只能大致說明    DWORD ResultProc(int hLine, const pRec pResult, DWORD dwUserData) {    char *pKey = NULL; //*為指標, initial 其值為nil. pkey則為一address    int  nLen = 0;            pKeyWord = new char[nLen];         GetValue (pResult->pszResult, pKey, &nLen); // & 為address之意, delphi相對為@, 故GetValue應為傳入一const 取得pkey //及nlen之值. 在C中傳入之值須為address才可更改其值如同delphi 之var //若用delphi重寫getvalue, 此兩變數均應加var 之modify //若直接呼叫, pkey可宣告為string, 傳入時pchar(pkey) (也可宣告為pchar) //nlen宣告為integer 傳入 @nlen //pResult->pszResult, ->表示pResult為一pointer, 在delphi中class object均為reference, 故可直接用pResult.取代, 但須看此type在delphi中如何宣告 cout<<"The Result is: "<
pszResult<
//這是output結果, delphi可用writeln取代. endl是#$0d#$0a即換行
 
        cout<<"The Key is: "<
Key<nCon<
//傳回值 delphi可用result:=0;

}
pResultNotify->fnNotify = &ResultProc; 

//&ResultProc為此process之address, delphi中可用@ResultProc
         
        
nj825
一般會員


發表:3
回覆:7
積分:2
註冊:2002-04-21

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-08-18 19:14:46 IP:61.70.xxx.xxx 未訂閱
多謝 ccchen 前輩的說明, 在此把未說明部份再整理一下...請前輩再幫忙一下,小弟真搞不懂那些宣告部份,謝謝~~ typedef unsigned long HASRLINE; typedef unsigned long DWORD; typedef struct _Main_RESULT { char *pszResult; char *pszLoma; int nCon; } Main_RESULT, *PMAIN_RESULT; typedef DWORD (*FNRESULTNOTIFY)(HASRLINE hLine, const PMAIN_RESULT pResult, DWORD dwUserData); typedef struct _MAIN_RESULTNOTIFY { FNRESULTNOTIFY fnNotify; DWORD dwUserData; } MAIN_RESULTNOTIFY, *PMAIN_RESULTNOTIFY; DWORD ResultProc(HASRLINE hLine, const PMAIN_RESULT pResult, DWORD dwUserData) { .... .... return 0L; } // 以下為程式中使用該 struct 的一段 PMAIN_RESULTNOTIFY pResultNotify = new MAIN_RESULTNOTIFY; pResultNotify->fnNotify = &ResultProc;
系統時間:2024-04-18 8:25:22
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!