TStringField how to format for display ? lazarus / 16-Databases ---------------------------------------------------------------------- lazguy · 2011-05-23 19:28 Hello Everybody !!!!! I need to format a TStringField (Zeos) like DisplayFormat for numeric field, but TStringFields don't have DisplayFormat property, and EditMask property is only for edition, but i only need for display, not edition. Help me please. Thank you in advance. ---------------------------------------------------------------------- CaptBill · 2011-05-23 19:39 You mean you need lots of formats to pick from or need just a specific format? ---------------------------------------------------------------------- Zoran · 2011-05-23 21:23 Use the field's OnGetText event to display what you need. ---------------------------------------------------------------------- lazguy · 2011-05-24 01:31 I am using a dynamically created TzQuery (to query a Firebird/Interbase Database), so, no components dropped on a Data Module or Form, passed as a parameter to a generic form with a StringGrid (read only) that have it's columns dynamically created according to the Query that is passed as a parameter to this generic form. The objective is to allow the user choose for example one product among a list of products that fits on a determined context. (This generic form is used in various situations, not only to choose products. I can use it to choose whatever I want) On the numeric fields of this TzQuery (for example Quantity) I can use the property DisplayFormat with the format desired for that field. (It is displayed correctly – formated – on the StringGrid) The Product code field is a varchar(10) with a string of 10 numbers (for example 1234567890). I would like to format this TstringField this way 123.45.6789-0 only for display. I would like to try to not pass the field format (for each field of the query) as a parameter to this generic form to make the “function call” as simple as possible, without to many parameters. ---------------------------------------------------------------------- CaptBill · 2011-05-24 06:25 Build a wrapper around the Tstringslist on the form. Then just make your own simple parsing setup for whatever format you need in this new class structure. Each format with its own function call. Or a singular call with a long case statement to use the 'type' field to name case statement choices. But you need to tell it which format you need somehow. You could maybe append the data with a token value because you will be parsing it anyway...But I guess the question then is, what do you mean by 'simple as possible'...Do you mean simple right now or simple as in future maintenance? Probably simplest to have the extra function parameter. ---------------------------------------------------------------------- lazguy · 2011-05-24 18:10 Thank you CaptBill. There is no property of the TZquery I can use for that ? For example, my query can return 4 columns (Two string field type, one integer field type and one float field type ). The grid will show this 4 fields. One of these string fields will not have a format (for example a name). The other string field will have a format (for example a phone number (1234-5678) the – character of the phone number is not stored in the database it will only be shown in the StringGrid). The integer field will not have a format. The float field can be formatted as '###,##0.00' so when this float field have a value of 10 it will be displayed in the StringGrid as 10,00 (and not 10 as it will be displayed if I not have a DisplayFormat property set to the format string I wrote above ('###,##0.00')). The query can be anything, it is a generic form with a generic StringGrid to display the results of any query. The code I am using for the numeric fields (that is working fine, is OK) is the following: TFloatField(dm.QConsulta.Fields[2]).DisplayFormat := '0.000'; How to do the same thing with a TstringField? Thank you very much in advance. ---------------------------------------------------------------------- CaptBill · 2011-05-24 21:45 This is the perfect opportunity to learn to utilize the class/object model, that is what truly sets Lazaruse/FPC ahead  of the game IMO. By learning how to 'descend' from another class will show you what Lazarus can actually do. By the way, I just did what I call my first one the other day. I would be glad to help work it out just for learning myself. Here is how easy it is...this is a Tspeedbutton that I 'descended' from that gives the button data 'fields' (x,y,z....) so the button becomes a bucket for data...Took me 10 minutes. But it is really how you should approach it in Laz Quote  TDbButton=class(Tbgrabutton)        private            fxidx:integer;            fyidx:integer;            fxval:double;            fyval:double;        protected            procedure click;override;        public            property Xidx:integer  read fxidx write fxidx;            property Yidx:integer  read fyidx write fyidx;            property Xval:double  read fxval write fxval;            property Yval:double  read fyval write fyval;            property onClick ;    end;  All you need is to read the data from the query into TYourClass then TYourClass will handle it from there. ---------------------------------------------------------------------- lazguy · 2011-05-25 15:54 Thank you VERY, VERY much CaptBill I'll try to "play" a little in the "playground". I hope to have success. It will be a good learning. Regards.