come ho convertire la stringa GUID da WideString a stringa unicode
-
25-10-2019 - |
Domanda
ho questo problema, facendo:
function GenGuid: String;
var
guid: TGuid;
begin
CreateGuid(Guid);
Result := GuidToString(Guid);
end;
E 'restituire un GUID in formato stringa. Ma io come faccio a convertire un WideString a UnicodeString? Ho bisogno di avere il GUID in formato stringa unicode. Grazie mille.
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;
In questo modo, t tornare 148-124 sempre e non ASCII del singolo carattere. Se non faccio ord () quindi visualizzare char correttamente.
Soluzione
Non sono sicuro se questo è ciò che si vuole veramente.
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;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow