Problem - space characters added behind text in DBGrid lazarus / 16-Databases ---------------------------------------------------------------------- Tom83 · 2010-11-25 08:18 Hi, I have a Firebird database (using UTF8 encoding). I connect to the database with TIBConnection component and I set TIBConnection.CharSet to 'UTF8'. Now I have the following problem with displaying values from char(n) columns: In the database I have a column: code char(3) I insert a value to this column, e.g. 'ABC'. When I display the value of this column in FlameRobin, it works correctly, there is 'ABC'. But when I display the value in DBGrid or other database components, there is 'ABC         ', so it added 9 spaces behind the text. The same problem occurs when I assign the value of the column to the variable: var A: string; . . . A:=SQLQuery1.FieldByName('Code').AsString; In A there isn't 'ABC', but there is 'ABC         '. I know I can simply delete these unwanted spaces, but is there another solution (better and more comfortable) how to get rid of these additional spaces? ---------------------------------------------------------------------- Lacak2 · 2010-11-25 09:32 Can you look at SQLQuery1.FieldByName('Code').DataSize what value it returns ? ---------------------------------------------------------------------- Tom83 · 2010-11-25 09:43 It returns 13. ---------------------------------------------------------------------- Lacak2 · 2010-11-26 04:58 May be, that 3*4+1=13 (  3-as character size of column char(3)  4-as max.count of bytes per character in UTF-8  1-as null string terminator char(3) field si mapped to ftFixedChar so trailing blanks are not removed. In case of varchar(3) trailing blanks will not present (I hope ;-)). You can remove these unwanted spaces using TField.OnGetText and there use trim() ---------------------------------------------------------------------- Tom83 · 2010-11-28 15:36 Thank you, I think it will work, but I need more information . My idea was to write a procedure: Code: [Select]procedure TForm1.DeleteSpaces(Sender: TField; var aText: string; DisplayText: Boolean = true); begin   aText:=Trim(Sender.AsString); end; Then to assign this procedure as an event handler for all the fields that are of ftFixedChar DataType: Code: [Select]for I:=0 to SQLQuery1.FieldCount-1 do   if SQLQuery1.Fields[I].DataType=ftFixedChar then     SQLQuery1.Fields[I].OnGetText:=@DeleteSpaces; But I don't know where to put this code. When the SQLQuery is inactive, there are no fields, so I can't assing them the OnGetText event handler. I tried to put the code to SQLQuery.AfterOpen event handler, but it still doesn't work. Probably because the fields are already filled with data, so the event OnGetText was already executed. Or is there something wrong with DeleteSpaces procedure? ---------------------------------------------------------------------- Lacak2 · 2010-11-29 06:36 Your code seems ok, also AfterOpen is right place. OnGetText is called when component request data for displaying or editing. Can you test if procedure DeleteSpaces is realy called ... may be, when you scroll in DBGrid ? ---------------------------------------------------------------------- Tom83 · 2010-11-30 21:44 OK, now it works, the problem was that the Fields.DataType of char(n) columns was not ftFixedChar, but ftString.