how i convert guid string from widestring to unicode string
-
25-10-2019 - |
Question
i have this problem, doing:
function GenGuid: String;
var
guid: TGuid;
begin
CreateGuid(Guid);
Result := GuidToString(Guid);
end;
It return a guid in string format. But i how do to convert a widestring to unicodestring? I need to have the guid in unicode string format. Thanks very much.
UPDATE
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;
Doing so, t return 148-124 always and not ascii of single character. If i not do ord( ) then display char correctly.
Solution
I'm not sure if that's what you really want.
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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow