Accessing DBGrid-Bufdataset data lazarus / 16-Databases ---------------------------------------------------------------------- iru · 2014-01-05 23:13 Gentlefolk, I have a DBGrid-Datasource-BufDataset combination. All fields are strings. I have to check the data input in one field. It is athletics performance data and which can be input in several forms, for example, 123456, 1234.56, 12:34.56. This data must be saved in one format 12:34.56. I can check individual characters using the OnKeyUp/Down but need to check for multiple colons and decimal points, etc. I can pick the "Enter" key at the end of the input but at that point cannot find the accumulated input string in the DBgrid fields or in the BufDatase.FieldByName('perf').AsString. Can anyone tell me where I can access the string of data that has been input? Thanks, Ian. ---------------------------------------------------------------------- mangakissa · 2014-01-06 08:09 Why can't you use BufDatase.FieldByName('perf').AsString for validating? DBGrid is nothing more than a visualization of your data. Try using OnSetText to format your data. But this isn't changing your data to the right format. ---------------------------------------------------------------------- howardpc · 2014-01-06 09:10 Quote from: iru on January 06, 2014, 12:13:54 amCan anyone tell me where I can access the string of data that has been input? It depends at what point in the editing process you want to be able to intervene. If you want per-cell validation, then one occasion is provided by the grid's OnEditingDone event. If you want per-record validation you can use the datasource's OnUpdate event. An example of using the grid's OnEditingDone event would be something like the following (you need to provide a customised boolean Validated() routine according to your requirements): Code: [Select]procedure TForm1.DBGrid1EditingDone(Sender: TObject); var   s: string; begin   s:=DBGrid1.SelectedField.AsString;   if Validated(s)     then ...   else ...; end; ---------------------------------------------------------------------- iru · 2014-01-06 09:32 Thank you for the responses, I will investigate. I have been down the path of BufDatase.FieldByName('perf').AsString for validating. The current input is not there at the point where I am checking. The input process is as follows: The computer user inputs the data in one of the various forms. I can use the OnKeyUp/Down code to check individual characters OK. If for example the input is a letter rather than a digit, sound a beep, return #0 so no action is taken. At the end of he input the computer user hits "enter" I then need to "parse" the input string looking for odd things like two colons, a colon and no decimal, etc. If any of these are found, sound a beep, return #0 and therefore stay in the cell. If no errors are found if necessary convert any of the forms of input to the standard 12:34.56 update the database and then continue on in the next cell. To further compound things the performance may be like 12:34.56h ("h" for hand timing) or the input may be DQ (disqualified). DNS, DNF, etc. Once again thanks, Ian. ---------------------------------------------------------------------- iru · 2014-01-06 21:49 I have done some further testing. A requirement is that if a validation error is found control stays in the cell where the error occurred. I tried the 'OnEditDone'. At the end of the input string hit 'Enter' and the OnEditDone fires and I can access the input string via dataset.FieldByName('perf').AsString. That's the good news, the bad is that the use of OnEditDone inhibits the OnKeyUP/Down event on the Enter key so I cannot replace the Enter key with #0 and stay in the cell. There is no exit or control capability on OnEditDone. If I use it control is passed to the next cell from the OnEditDone. Still chasing...... Ian ---------------------------------------------------------------------- iru · 2014-01-08 21:34 Gentlefolk, I have been looking around and came across "http://wiki.lazarus.freepa scal.org/Grids_Reference_Page#Grid_Cell_Editors". This gives many examples and explanations of the use of StringGrids/Grids/DBgrids and the utilisation of editors within these. I tackled the DBGrid example and added a TEdit object which acts as the editor. Through the Tedit and its events I can get at the text string via "Edit1.Caption". That's the good news, the bad news is that I seem to have getting out of the "Edit" and the normal DBGrid inter cell up/down are not working. Chasing on...... Ian. ---------------------------------------------------------------------- iru · 2014-01-12 10:06 Gentlefolk, I have done a lot of reading on this. My original structure was dbgrid-bufdataset-tsqlquery-firebird. This was to isolate the user-grid from the database and concurrent access issues. Looking at the stringgrid it stores data and I could use a structure of stringgrid-tsqlquery-firebird which would in some ways be simpler. I would have to write some code between the stringgrid and sqlquery but this would hang off key/up/down, endedit type events and be do- able. So I inserted a stringgrid and and some event handlers. Woops, the gdb crashes on bad breakpoints and I get a SIGSEV crash as the program terminates. Time to roll things back and do some more looking..... Ian. ---------------------------------------------------------------------- iru · 2014-01-16 01:35 Gentlefolk, Just a final note on this. Uninstalled lazarus including the files up in "localappdata". Re-installed Lazarus, loaded all packages to the project and tried again. No errors on GDB breakpoints. The SIGSEV that had commenced occurring when the program shut down no longer occurs. Now to look at StringGrid........ Ian