Not Delphi, learn to use the Delphi wrote a read-write card operation ocx, encounter a problem cannot be solved, hope to get you a great god help! Thank you very much!
Problem description:
Browser doesn't ocx method return values (BSTR * type of JSON string);
1. The read-write card operation call third-party DLL,
2. If you don't call DLL function, ocx - & gt; The browser is normal,
3. DLL function call, call DLL (the return value is normal), normal ocx function performed normally, the browser take less than ocx return value (there will be a memory card reader to the exception, write a card return value undefined),
4. Modify the ocx DLL function in the statement, change the parameters of type string to pchar, DLL function call, the abnormal returns, ocx - & gt; The browser is normal,
Guess: is it possible that the DLL problems caused by parameters of type string, or after throw the exception in the DLL's code has caused the unknown problems?
External function declaration:
//read card
The function ic_readcard (port: integer;
S_companycode: string;
Var cardtype: integer;
Keycode: string;
Var userid: pchar;
Var meterno: pchar;
Var orderlsh: pchar;
Var price: real;
Var totalmoney: real;
Var readflag: integer) : integer; Stdcall;
External 'SmartCard. DLL' name 'ic_readcard';
//write transaction data to the card to buy gas 0 1 card
The function ic_writeorder (port: integer; DLLPSW s_companycode: string;
Ordertype: integer;
Userid, meterno orderlsh, keycode: string;
Price, totalmoney: real; PriceInMeter: integer) :
An integer. Stdcall;
External 'SmartCard. DLL' name 'ic_writeorder';
Ocx read-write card methods:
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- read card
The function TAxCardReader. Read: WideString;
Var
Price, totalmoney: real;
Cardtype readflag: integer;
Userid, meterno orderlsh: pchar;
Companycode, keycode: pchar;
MSG, temp: WideString;
The begin
Try
Cardtype:=255;
Userid:=AllocMem (9);
Meterno:=AllocMem (8);
Orderlsh:=AllocMem (16);
Companycode:=';
Keycode:=';
Readflag:=1;
Price:=0;
Totalmoney:=0;
S_msg:=';
Try
WriteWorkLog (' -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- start reading card -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - ');
I_result:=ic_readcard (10, companycode, cardtype keycode, userid, meterno, orderlsh, price, totalmoney, readflag);
//i_result:=0;
WriteWorkLog (' -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the end result: the card reader to the '+ inttostr (i_result) + "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --');
If i_result=0 then
The begin
Temp:='111111';
End
The else
The begin
MSG:=GetMessage (i_result);
Temp:='{state: 1, the message: "' + MSG + '"} ";
end;
The finally
The begin
FreeMem (userid);
FreeMem (meterno);
FreeMem (orderlsh);
end;
end;
Except,
On e: the Exception do
The begin
Temp:='{state: 1, the message: "read card to control internal abnormal:' + e.M essage + '"}";
end;
end;
Result:=temp;
WriteWorkLog (' -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the result read card function has been completed: "+ result +" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ');
end;
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
write cardThe function TAxCardReader. Write (const userid, meterno orderlsh: WideString;
Price, totalmoney: Single) : WideString;
Var
P_port p_ordertype, p_PriceInMeter: integer;
P_dllpsw p_s_companycode, p_keycode: pchar;
P_userid p_meterno, p_orderlsh: pchar;
P_price p_totalmoney: real;
MSG, temp: WideString;
The begin
P_dllpsw:=';
P_s_companycode:=';
P_keycode:=';
P_userid:=';
P_meterno:=';
P_orderlsh:=';
Try
P_dllpsw:=AllocMem (50);
P_s_companycode:=AllocMem (50);
P_keycode:=AllocMem (50);
P_userid:=AllocMem (50);
P_meterno:=AllocMem (50);
P_orderlsh:=AllocMem (50);
P_port:=0;
P_ordertype:=1;
P_PriceInMeter:=1;
Afa821b0bed2151 p_dllpsw:='1';
P_s_companycode:=';
P_keycode:=';
P_userid:=pchar (Utf8ToAnsi (Utf8Encode (userid)));
P_meterno:=pchar (Utf8ToAnsi (Utf8Encode (meterno)));
P_orderlsh:=pchar (Utf8ToAnsi (Utf8Encode (orderlsh)));
P_price:=price;
P_totalmoney:=totalmoney;
WriteWorkLog (' -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- start write card -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - ');
Try
I_result:=ic_writeorder (p_port p_dllpsw, p_s_companycode, p_ordertype,
P_userid p_meterno, p_orderlsh p_keycode, p_price, p_totalmoney, p_PriceInMeter);
I_result:=1;
WriteWorkLog (' -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- write card end result: "+ inttostr (i_result) +" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ');
If i_result=0 then
The begin
Temp:='{state: 0, the message: "write card success"} ";
End
The else
The begin
MSG:=GetMessage (i_result);
Temp:='{state: 1, the message: "' + MSG + '"} ";
end;
Except,
On e: the Exception do
The begin
Temp:='{state: 1, the message: "read card to control internal abnormal:' + e.M essage + '"}";
end;
end;
The finally
The begin
FreeMem (p_dllpsw);
FreeMem (p_s_companycode);
FreeMem (p_keycode);
FreeMem (p_userid);
FreeMem (p_meterno);
FreeMem (p_orderlsh);
end;
end;
Result:=copy (temp, 0, length (temp));
WriteWorkLog (' -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- write card function complete results: '+ temp + "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --');
end;