In Delphi, you can use the TGUID type to represent a globally unique identifier (GUID). A GUID is a 16-byte (128-bit) value that is used to uniquely identify objects, such as database records or COM objects.
To create a new GUID, you can use the CreateGUID function, which generates a new, random GUID. You can then assign the result to a TGUID variable. For example
1 2 3 4 5 |
var MyGUID: TGUID; begin MyGUID := CreateGUID; end; |
To generate a new GUID as a string, you can use the GUIDToString function, which converts a TGUID value to a string representation in the form ‘{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}’. For example
1 2 3 4 5 6 7 |
var MyGUID: TGUID; MyGUIDString: string; begin MyGUID := CreateGUID; MyGUIDString := GUIDToString(MyGUID); end; |
To convert a string representation of a GUID to a TGUID value, you can use the StringToGUID function. For example
1 2 3 4 5 6 7 |
var MyGUIDString: string; MyGUID: TGUID; begin MyGUIDString := ‘{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}’; MyGUID := StringToGUID(MyGUIDString); end; |
Leave a Reply