DBGrid and ZEOS data display lazarus / 16-Databases ---------------------------------------------------------------------- iru · 2010-04-19 23:59 Gentlefolk, Using laz 0.9.28, ZEOS 6.6.6 and Win XP with SP-3. I have a DBGrid>DataSource>(ZQuery, ZUpdateSQL) structure. All works well, can display contents of required tables, can insert/update records in table. I have a requirement to progromatticaly set values in some fields, use appropriate SQL in ZUpdateSQL and fill the dataset field by means of ZQuery.FieldByName('xxx').AsString := 'zzz', etc. All works well. I also wish to input some data in a cell and then reformat it before writing to the database. For example input of '1234' is converted to a stand format of '00:12.34'. Do the conversion, save the formatted data into the dataset field with ZQuery.FieldByName('xxx').AsString := Perf (contents 00:12.34). The following happens:   The original unformatted data is still displayed in DBGrid and is also written to the database record.   If I update the field in the 'BeforePost" event the record the DBGrid cell displays the formatted data and the formatted data is written to the table record. The problem is that I would like the formatted data displayed in the DBGrid when the user presses as an indication that the input data is correct (no alpha characters, etc). Tried all sorts of things on all sorts of events, no luck. Any suggestions, etc. Ian ---------------------------------------------------------------------- jesusr · 2010-05-04 19:14 Using persistent fields (see right click ZQuery and select "edit fields") then you can use field events OnGetText and OnSetText to transform the text is shown in any db control, included the grid. A link taken from google search: http://www.techtricks.com/delphi/datapcts.php ---------------------------------------------------------------------- iru · 2010-05-04 21:44 Thanks for the response. You appear to be on the right track however there appears to be a bug in the ZEOS/Lazarus "edit fields" code. Use "add field", select field "reg", field "name" is added, select field "name" to add and you get "duplicate field" (for field reg). One step forward, one step back....... Thanks once again, Ian ---------------------------------------------------------------------- iru · 2010-05-05 02:04 If I   remove all the fields from the field editor (rather than one by one)   click on add   Select ALL the fields all the fields get added. Program compiles and runs, In the event handler on the required field I see the formatted data. Gets displayed on the screen. One again, thanks for the response. On to the next issue.... Ian ---------------------------------------------------------------------- iru · 2010-05-05 07:11 Woops, A little eager on this. A bulk "add" of all fields results in all fields except ONE being added. All attempts to add the field "age" result in a "duplicate field message" for a field named "name". Similar to previously reported. ian ---------------------------------------------------------------------- garlar27 · 2010-05-05 09:55 I had the same problem using TDbf: it works ok on almost every table, but, in some cases I had the same error. In order to solve this problem you have to find the field that causes te error (the fiel thats inserted with wrong name an probably type), to find out which fields are involved add field "age" and look the property FieldName, if is = "age" then you will have to find the field that's inserted with wrong FieldName then:    Workaround:         1- add all fields         2- remove the "problematics" fields (age and te other one)         3- add the field which is added with a wrong name         4- correct it's properties in object inspector (pay attention to the kind of field you can't use a TFloatField to read a TStringField).         5- add remaining field/s. Good luck!! ---------------------------------------------------------------------- iru · 2010-05-05 21:44 All done, some fiddling around, delete, add,modify, etc. I now have all the fields and my modified data is now displayed immediately after I hit . Thanks to all, Ian. ---------------------------------------------------------------------- iru · 2010-05-06 23:47 Gentlefolk, Some further work indicates that this problem appears to be resolved in ZEOS 7.0. Ian