R
rsjd
Unregistered / Unconfirmed
GUEST, unregistred user!
上个帖子我已经结了,但是却发生了新的问题,新开一贴,不好意思,本人分不多,只给100分,我做了个试验,函数库DLL代码如下:
procedure test(const str: PChar
var outStr: PChar)
stdcall;
var strn: string;
begin
strn := str;
if Length(strn) &gt
0 then
begin
strn := StringReplace(strn, '/', '//', [rfReplaceAll]);
strn := StringReplace(strn, '''', '/''', [rfReplaceAll]);
strn := StringReplace(strn, '"', '/"', [rfReplaceAll]);
end;
outStr := PChar(strn);
end;
exports test;
VB中调用的代码如下:
Private Declare Sub test Lib "unit1.dll"
(ByVal str As String, outStr As String)
Public Function vbsToJs(ByVal str As String) As String
Dim strOut As String
test str, strOut
vbsToJs = strOut
End Function
结果仍然不正确,还是会丢失字符,也就是说结果不可预料,但是且慢,只要我把DLL中的StringReplace改为Peter Morris的FastStrings单元中的FastAnsiReplace,结果戏剧性地发现,不管我怎么搞,结果都完全正确,这下我就更加搞不明白了,这是DELPHI的BUG呢,还是我哪里又出漏子了?
原来的帖子请看:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2997058
procedure test(const str: PChar
var outStr: PChar)
stdcall;
var strn: string;
begin
strn := str;
if Length(strn) &gt
0 then
begin
strn := StringReplace(strn, '/', '//', [rfReplaceAll]);
strn := StringReplace(strn, '''', '/''', [rfReplaceAll]);
strn := StringReplace(strn, '"', '/"', [rfReplaceAll]);
end;
outStr := PChar(strn);
end;
exports test;
VB中调用的代码如下:
Private Declare Sub test Lib "unit1.dll"
(ByVal str As String, outStr As String)
Public Function vbsToJs(ByVal str As String) As String
Dim strOut As String
test str, strOut
vbsToJs = strOut
End Function
结果仍然不正确,还是会丢失字符,也就是说结果不可预料,但是且慢,只要我把DLL中的StringReplace改为Peter Morris的FastStrings单元中的FastAnsiReplace,结果戏剧性地发现,不管我怎么搞,结果都完全正确,这下我就更加搞不明白了,这是DELPHI的BUG呢,还是我哪里又出漏子了?
原来的帖子请看:
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2997058