07-08-19, 06:00 PM
كود :
procedure TForm1.Button1Click(Sender: TObject);
var
MyGuid0, MyGuid1 : TGUID;
begin
{ Create a new GUID from the string representation. }
MyGuid0 := StringToGUID('{00020400-0000-0000-C000-000000000046}');
Memo1.Lines.Add('The GUID is: ' + GUIDToString(MyGuid0));
{
Accessing GUID's internal fields
Using the Format function to obtain the same output as GUIDToString
}
Memo1.Lines.Add(Format('GUID using formatting is: ' +
'{%0.8X-%0.4X-%0.4X-%0.2X%0.2X-%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X}',
[MyGuid0.D1, MyGuid0.D2, MyGuid0.D3,
MyGuid0.D4[0], MyGuid0.D4[1], MyGuid0.D4[2], MyGuid0.D4[3],
MyGuid0.D4[4], MyGuid0.D4[5], MyGuid0.D4[6], MyGuid0.D4[7]]));
{ Autogenerate a random GUID at run time. }
if CreateGUID(MyGuid1) <> 0 then
Memo1.Lines.Add('Creating GUID failed!')
else
Memo1.Lines.Add('The generated guid is: ' + GUIDToString(MyGuid1));
{ Generating second random GUID. }
CreateGUID(MyGuid0);
{ Testing if two guids are equal. }
if IsEqualGUID(MyGuid0, MyGuid1) then
Memo1.Lines.Add('This cannot happen! CreateGUID guarantees that ' +
'2 randomly generated GUIDs cannot be equal!');
end;
النتيجة
كود :
The GUID is:
{00020400-0000-0000-C000-000000000046}
GUID using formatting is:
{00020400-0000-0000-C000-000000000046}
The generated guid is:
{D1CCAB8F-F534-4034-8CF5-619101F03B9D}