Tomas Rutkauskas
I'm looking for a function to create a GUID. I don't want to create a COM object or
something, I just need a sort of 'Session ID' for a special database procedure.
Answer:
1 uses
2 ActiveX;
3
4 function GenerateKey: string;
5 var
6 MyGUID: TGUID;
7 MyWideChar: array[0..100] of WideChar;
8 begin
9 {First, generate the GUID:}
10 CoCreateGUID(MyGUID);
11 {Now convert it to a wide-character string:}
12 StringFromGUID2(MyGUID, MyWideChar, 39);
13 {Now convert it to a Delphi string:}
14 Result := WideCharToString(MyWideChar);
15 {Get rid of the three dashes that StringFromGUID2() puts in the result string:}
16 while Pos('-', Result) > 0 do
17 Delete(Result, Pos('-', Result), 1);
18 {Get rid of the left and right brackets in the string:}
19 while Pos('{', Result) > 0 do
20 Delete(Result, Pos('{', Result), 1);
21 while Pos('}', Result) > 0 do
22 Delete(Result, Pos('}', Result), 1);
23 end;
|