I Think I have a big knowledge gap to jump over but don't get the Problem yet.
In my Application I use MS SQL Server to automatic create special GUIDs. The Default Value of that Column is :
(CONVERT([binary](16),newid()))
which leads to something like that
0x0184F4422C58EA4A95B366E2F90F5973
Everything works fine, but sometimes I need to write that Binary(16) into logging File. I Have a Function that generates that GUIDs for me, feel Free to use. For Sql query I use FireDAC Query. The Function looks like that:
function GetNewGUID: variant;
const
cCREATENEWGUID = 'select (CONVERT([binary](16),newid())) as GUID';
var
lquery: TFDQuery;
begin
try
lquery := TFDQuery.Create(nil);
try
lquery.Connection:=MyFDConnection;
lquery.Open(cCREATENEWGUID);
Result := lquery.FieldByName('GUID').AsVariant;
finally
lquery.Free;
end;
Except
on e: Exception do
// Some logging here
end;
end;
That gives me perfectly working Variant. But when I like to display that as String I don't get it. I tried vartostr, that gives me ???? I tried TEncoding.ANSI.GetString, that gives me some strange chars
What I get so far, my Variant is VarArray and type of Array Byte.
GUID, instead of usingSysUtils.CreateGUID()andSysUtils.GUIDToString(), or evenSysUtils.TGUIDHelper.NewGuid().ToString()??