如何将GUID字符串从widestring转换为Unicode字符串
-
25-10-2019 - |
题
我有这个问题,这样做:
function GenGuid: String;
var
guid: TGuid;
begin
CreateGuid(Guid);
Result := GuidToString(Guid);
end;
它返回字符串格式的GUID。但是,我该如何将宽大的速度转换为Unicodestring?我需要具有Unicode字符串格式的GUID。非常感谢。
更新
function myguid: string;
var
i: Integer;
s: string;
Guid: TGuid;
t: byte;
begin
CreateGuid(Guid);
s := GuidToString(Guid);
for i := 1 to Length(s) do
begin
t := Ord(MidStr(s, i, 1));
writeln (t);
end;
Result := .... // for now not need, just a test
end;
这样做,t总是返回148-124,而不是单个字符的ASCII。如果我不执行ord(),请正确显示炭。
解决方案
我不确定这是否是您真正想要的。
uses
ComObj, ActiveX;
function CreateGuid: string;
var
GUID: TGUID;
begin
Result := '';
if CoCreateGuid(GUID) = S_OK then
begin
Result := IntToHex(GUID.D1, 8) +
IntToHex(GUID.D2, 4) +
IntToHex(GUID.D3, 4) +
IntToHex(GUID.D4[0], 2) +
IntToHex(GUID.D4[1], 2) +
IntToHex(GUID.D4[2], 2) +
IntToHex(GUID.D4[3], 2) +
IntToHex(GUID.D4[4], 2) +
IntToHex(GUID.D4[5], 2) +
IntToHex(GUID.D4[6], 2) +
IntToHex(GUID.D4[7], 2);
end;
end;
不隶属于 StackOverflow