R
rsjd
Unregistered / Unconfirmed
GUEST, unregistred user!
函数库:
library strstr;
uses
Windows,SysUtils;
function strToJS(const str: PChar): PChar
stdcall;
var
Len: Cardinal;
strn: String;
begin
Len := StrLen(str);
if Len &gt
0 then
begin
try
SetLength(strn, 256);
strn := strPas(str);
strn := StringReplace(strn, '''', '/''', [rfReplaceAll]);
strn := StringReplace(strn, '"', '/"', [rfReplaceAll]);
strn := StringReplace(strn, '/', '//', [rfReplaceAll]);
Result := PChar(strn);
except
Result := PChar('');
end;
end
else
Result := PChar('');
end;
exports
strToJS;
begin
end.
看起来一切正常,但就是在使用时,无缘无故有时会丢失字符,比如字符串'金属垫片(齿形)'输出正常,但字符串'金属垫片(不锈钢)'就会在把主程序中后面两个字符串丢失,为什么呢?
library strstr;
uses
Windows,SysUtils;
function strToJS(const str: PChar): PChar
stdcall;
var
Len: Cardinal;
strn: String;
begin
Len := StrLen(str);
if Len &gt
0 then
begin
try
SetLength(strn, 256);
strn := strPas(str);
strn := StringReplace(strn, '''', '/''', [rfReplaceAll]);
strn := StringReplace(strn, '"', '/"', [rfReplaceAll]);
strn := StringReplace(strn, '/', '//', [rfReplaceAll]);
Result := PChar(strn);
except
Result := PChar('');
end;
end
else
Result := PChar('');
end;
exports
strToJS;
begin
end.
看起来一切正常,但就是在使用时,无缘无故有时会丢失字符,比如字符串'金属垫片(齿形)'输出正常,但字符串'金属垫片(不锈钢)'就会在把主程序中后面两个字符串丢失,为什么呢?