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

(新手問題) C++語法改成DELPHI語法

尚未結案
rookie
一般會員


發表:26
回覆:38
積分:12
註冊:2003-04-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-06-05 17:38:53 IP:61.220.xxx.xxx 未訂閱
請問一下....以下C++語法如何改成DELPHI ------------------------------------------------------------------- unsigned char BYTE ;    bool UseID::SelectID() {    BYTE ID[] = {'\x00', '\xA4', '\x04', '\x00', '\x07','\xA0', '\x00', '\x00', '\x00', '\x04', '\x90', '\x01'};    return Base::SendID(ID) == 0x9000 ? true: false; } -------------------------------------------------------------------- 謝謝各位大大的幫忙 發表人 -
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-06-06 09:17:13 IP:147.8.xxx.xxx 未訂閱
This is a guess since I have no idea about your class UserID. Is it inherited from class Base?    
function UseID.SelectID: boolean;
const
   ID: array[0..11] of byte = (
       $00, $A4, $04, $00, $07, $A0, $00, $00, $00, $04, $90, $01 );
begin
    Result := (Base(self).SendID(ID) = $9000);
end;
rookie
一般會員


發表:26
回覆:38
積分:12
註冊:2003-04-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-06-06 17:48:34 IP:61.220.xxx.xxx 未訂閱
謝謝william的回應 真是不好意思,問的太難懂了 我的問題是有關陣列的使用 -------------C -----寫的----DLL-------------------------------------- function IncomeingPDU(hContext :longint;PDU:ByteArr3):word;cdecl;external 'GM.DLL' name '@IncomeingPDU$qlpuc'; -----------------------TYPE------------------------------------------- TfncCnx = function (s : string) : THandle; ByteArr1 = array[0..15]of Byte; ByteArr2 = array[0..11]of Byte; ByteArr3 = array of Byte; -----------------------const------------------------------------------ ID: array[0..11] of byte = ( $00, $A4, $04, $00, $07, $A0, $00, $00, $00, $04, $90, $01 ); -----------------------CALL FUNCTION---------------------------------- procedure TForm4.FormActivate(Sender: TObject); VAR K:WORD BEGIN K:=IncomeingPDU(1,ID); END; 會有ERROR Incompatible types: 'Array' and 'dynamic array' -----------------然後我把他改成---------------------- var AAID:array of byteARR2; SetLength(AAID,Length(ID)); IDd:=ID; K:=IncomeingPDU(1,ID); 也會有Incompatible types: 'Array' and 'dynamic array' ------------------------------------------------------ DELPHI 的ARRAY 真的很難用 幫幫我吧!!!!!.........先謝了
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-06-06 20:33:59 IP:210.0.xxx.xxx 未訂閱
引言:function IncomeingPDU(hContext :longint;PDU:ByteArr3):word;cdecl;external 'GM.DLL' name '@IncomeingPDU$qlpuc';
Are you sure PDU is of type ByteArr3?
rookie
一般會員


發表:26
回覆:38
積分:12
註冊:2003-04-23

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-06-09 08:55:39 IP:61.220.xxx.xxx 未訂閱
Thx for william yes, i am sure and PDU is a dynamic array it create in C like: word IncomeingPDU(longint hContext;byte PDU[])
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-06-09 09:33:22 IP:147.8.xxx.xxx 未訂閱
引言:Thx for william yes, i am sure and PDU is a dynamic array it create in C like: word IncomeingPDU(longint hContext;byte PDU[])
Then I think it is not the dynamic array you used in Delphi. PDU should be PByteArray (if the size (hContext?) <32767) or simply PByte.
shaofu
高階會員


發表:5
回覆:136
積分:103
註冊:2003-01-07

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-06-09 10:04:48 IP:210.243.xxx.xxx 未訂閱
引言: DELPHI 的ARRAY 真的很難用 幫幫我吧!!!!!.........先謝了
如果你真的了解 Delphi 的 dynamic array, 就不會有問題了... 遇到問題, 最好先了解問題.. 直接硬幹.. 效果不好 @@... 我的看法與 william 前輩相同..
rookie
一般會員


發表:26
回覆:38
積分:12
註冊:2003-04-23

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-06-09 13:30:16 IP:61.220.xxx.xxx 未訂閱
謝謝兩位前輩的指教: 先撇開這個dynamic array問題不談 我還有一個問題想請教 -----------在C++---------------------------------------------- 假設說 ID 的function 宣告 word ID(INT IDNUM;byte SEND[];byte Receive[]) ----------------------------------------------------- ID function 的使用 BYTE SEND1[]={'\x00', '\xA4', '\x04', '\x00', '\x07'}; BYTE Receive1[]; WORD ID1; ID1=ID(2,SEND1,Receive1); COUT〈〈ID1;.......... COUT〈〈Receive1[0];............. COUT〈〈Receive1[1];......... .............    執行完以後因該可以哪到ID1,Receive1的值 -------------------------------------------------------- 那在DELPHI中宣告 function ID(IDNUM :INTEGER;SEND ARRAY OF BYTEbyte;Receive ARRAY OF BYTEbyte)word  ------------------------------------------ 使用 ID1:=ID(2,SEND1,Receive1); 可以哪到ID1,Receive1的值嗎?    還有DELPHI 有PASS BY reference  is like C 中有一段宣告 int *&A;與 int **&B 謝謝 發表人 - rookie 於 2003/06/09 16:57:51 發表人 - rookie 於 2003/06/09 18:05:59
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-06-10 09:35:52 IP:147.8.xxx.xxx 未訂閱
I wonder who is responsibe to deallocate the memory allocated for Receive1??? Despite that, I think your declaration in Delphi is wrong.    function ID(IDNUM:integer; SEND: PByte; Receive: PByte): word;    Bute Receive is pass by value??? I really can't understand your C++ code. Can you post the code for function ID?    Personally I never use int *&A in C/C , perhaps a simple var A: integer in Delphi may work? for int **&B, could it be var B: PInteger?
rookie
一般會員


發表:26
回覆:38
積分:12
註冊:2003-04-23

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-06-10 11:04:06 IP:61.220.xxx.xxx 未訂閱
THANKS FOR ANSWERING MY QUESTION There is a function declared in C++'s dll if i want to use that function in C I use below  ----------------------------------------------------------------- -----------------------------declar------------------------ Word (_cdecl *OutgoingAPDU) (HDEVICE_CONTEXT hContext,Byte APDU[],Byte ReceiveBuf[]); DLLInst=LoadLibrary("GM.DLL"); OutgoingAPDU = lpOutgoingAPDU) GetProcAddress(DLLInst, "@OutgoingAPDU$qlpuct2"); -----------------------------use---------------------- public ... WORD SendAPDU(BYTE *APDU, BYTE *resp); .... WORD RiEZReader::SendAPDU(BYTE *APDU, BYTE *resp) {     hDevice ==512;     return OutgoingAPDU(hDevice, APDU, resp); } it works good ----------------------------------------------------------------- I want to change to delphi but it is so hard for me all other functions workexcept Pass By reference value I declared function below in delphi ---------------------------------------------------------- {$R *.dfm} function OutgoingAPDU(hContext :longint; APDU:array of Byte;var ReceiveBuf:array of Byte):word;cdecl;external 'GM.DLL' name '@OutgoingAPDU$qlpuct2'; ------------------------use-------------------------------- function TForm4.OutAPDU(text :longint; APDU1:array of Byte;var Receive:array of Byte):word; begin RESULT:=OutgoingAPDU(text,APDU1, RECEIVE); ← I cannot Get any return from here end;
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-06-10 13:30:21 IP:147.8.xxx.xxx 未訂閱
The main point is you cannot use Delphi's native dynamic array here. Borland has its own memory manager in handling dynamic array and it certainly does not work with other non-Borland product (I even doubt it could work with BCB). Maybe the declaration looks like: function OutgoingAPDU(hContext: longint; APDU: PByte; ReceiveBuf: PByte):word;cdecl;external 'GM.DLL' name '@OutgoingAPDU$qlpuct2'; But then where is the memory allocated/freed for ReceiveBuf???
系統時間:2024-05-05 18:52:56
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!