Page 1 of 1
Uniqueidentifier string format
Posted: Wed 25 May 2011 07:42
by rosa
Hello,
I noticed that dbExpress creates TStringField for the UniqueIdentifier fields. Can I change the format of the resulting string somehow? In particular I'd like to remove curly brackets.
Posted: Wed 25 May 2011 11:36
by AndreyZ
Hello,
To remove curly brackets from the uniqueidentifier column, you can use persistent fields and the OnGetText event handler in the following way:
Code: Select all
procedure TMainForm.ClientDataSetuidGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
Text := Copy(Sender.AsString, 2, Length(Sender.AsString) - 2);
end;
Posted: Thu 26 May 2011 08:46
by rosa
AndreyZ wrote:Hello,
To remove curly brackets from the uniqueidentifier column, you can use persistent fields and the OnGetText event handler in the following way:
Code: Select all
procedure TMainForm.ClientDataSetuidGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
begin
Text := Copy(Sender.AsString, 2, Length(Sender.AsString) - 2);
end;
This is of course possible, but I can't use such approach(persistent fields) in my case. The application would have to handle every uniqueidentifier field this way explicitly, but it simply doesn't know them:-(( Moreover, the described solution might work with dbGrid, but not when applying filters on the dataset - I guess.
I'd rather have dbExpress driver (or the underlaying sql server client library) configured to behave the required way for every uniqueidentifier field in the database implicitly - if possible.
Posted: Thu 26 May 2011 12:19
by AndreyZ
You can cast uniqueidentifier fields to string in the following way:
Code: Select all
SQLQuery.SQL.Text := 'select cast(uid as varchar(40)) uid from tablename';
ClientDataSet.Open;