Saving data to ms access lazarus / 16-Databases ---------------------------------------------------------------------- daeroncs · 2007-03-24 09:23 I eventually found some information on how to connect to an ms access database that worked for me.  I am now trying to save some data to the database.  I generally try and avoid using data aware controls, so I am interested in using code for the purpose.  I have built a form and used it to retrieve data without too much difficulty, but when I try using Append and Post to save new data I get no runtime or design time errors, but the data doesn't make it into the database.  Are the SQLdb controls or is the underlying free pascal ODBC code buggy, or am I doing something wrong? I've had a lot of experience with Delphi, where the code for this is really straight-forward. ---------------------------------------------------------------------- matthijs · 2007-03-24 12:11 Post the relevant part of the code you are using to save data here and we might know what is going wrong. ---------------------------------------------------------------------- daeroncs · 2007-03-24 13:11 I understand what you are saying, but I suppose the problem is what is the relevant part? I have a class TOrganisation which has a procedure "NewRecord" that uses the Append command: Code: [Select] procedure TOrganisation.NewRecord; begin   with ContactsDM do   begin     OrgQry.Append;   end; end; This is called when a "New" button is clicked on the data entry form The same class has other procedures "EditRecord" and  "PostRecord" Code: [Select] procedure TOrganisation.EditRecord; begin   with ContactsDM do   begin     OrgQry.Edit;   end; end; procedure TOrganisation.PostRecord; begin   with ContactsDM do   begin     OrgQry.Post;   end; end; OrgQry is a TSQLQuery object that's wired to a TODBCConnection object.  There's also a TDatasource object and a TSQLTransaction object. This is called when the "Save" button is clicked: Code: [Select] procedure TMainForm.SaveBtnClick(Sender: TObject); begin   Org.EditRecord;   Org.OrgID := StrToInt(OrgIDText.Caption);   Org.OrgName := OrgNameEdit.Text;   Org.Descriptor := DescriptorEdit.Text;   Org.DateAdded := StrToDateTime(DateAddedText.Caption);   Org.Da]"]>Blockeddified := StrToDateTime(Da]"]>BlockeddifiedText.Caption);   Org.PostRecord; end; Org is an object of class TOrganisation. As you can see, none of it is exactly rocket science. After I posted it occurred to me (duh!) to set a breakpoint at the beginning of the SaveBtn procedure, and I got an error message to the effect that the file "dataset.inc" could not be found  when it got to the OrgQry.Edit line.  Searching for the file turned it up where I assume it was supposed to be, in "C:\lazarus\fpc\source\packages\fcl- db\src".  I added that directory to the  include files path, and ran the code again.  This time it found the include file and stepped through it until it got to TDataset.GetActive, at which point it popped the data entry form back into focus and ran no further:  Code: [Select] function TDataset.GetActive : boolean; begin   result := (FState <> dsInactive) and (FState <> dsOpening); end; Do you need to see any more code? ---------------------------------------------------------------------- daeroncs · 2007-03-26 03:29 I've got to confess to a dumb error, the result of which was that the program was attempting to save a record for a null primary key!  I didn't find this until I moved the code over to Delphi, which kindly provided me with a useful error message from the ODBC driver.  Neither Delphi nor lazarus like processing an Edit command on a dataset that's in Append mode, either... Having fixed those problems however, I still don't seem to be able to save the record in lazarus (now works fine in Delphi 2006).  I've just about worn out the F7 key on my keyboard stepping through lcl and fpc sourcecode, and ended up with the following lines added to the project's includes path: Code: [Select] C:\lazarus\fpc\2.1.3\source\packages\fcl-db\src\ C:\lazarus\fpc\2.1.3\source\rtl\ C:\lazarus\fpc\2.1.3\source\rtl\objpas\classes\ C:\lazarus\fpc\2.1.3\source\rtl\objpas\sysutils\ C:\lazarus\fpc\2.1.3\source\rtl\inc\ C:\lazarus\fpc\2.1.3\source\rtl\i386\ I don't understand why I need to put those paths in, given that there is a path to fpc source in the lazarus Environment settings?  It also seems to be a problem that no runtime error is generated if an inc file is not found unless you're already in debug mode from setting a breakpoint. I gave up part way through stepping through the code that runs after my Post command after what seemed like hours of "F7-ing" I'm running the lazarus 0.9.21 on a pc running Windows Vista, and the Delphi 2006 code on a pc running XP.  (Well, I can't install Delphi 2006 on Vista, can I?) ---------------------------------------------------------------------- Marc · 2007-03-26 09:21 Recently the paths of the fcl were changed, I guess the version (telling 0.9.21 for a nightly isn't enough) of lazarus you use doesn't have those changed paths, so it cannot find them. BTW, I hope you did add those includes to the "other sources" path and not to the "include" path of your project ---------------------------------------------------------------------- daeroncs · 2007-03-26 13:29 I downloaded lazarus and fpc as a package from the nightly builds - it's dated the 20th March..  I would have thought that the search paths ought to match, since I downloaded them together, but I suppose it was a nightly build, so one mustn't be too precious about it.  Maybe I'll grab the latest nightly build and see how that works... Meanwhile I've succeeded in getting Delphi 2006 working on Vista, so maybe I'll go with that instead... I didn't add the sources to other sources, I added them to includes.  Why was this wrong? ---------------------------------------------------------------------- Vincent Snijders · 2007-03-26 13:36 Marc, I think the problem is that the debugger cannot find the FCL (or RTL) sources, because debugger doesn't use the information from the code tools and the fpc source path in the environment options. ---------------------------------------------------------------------- Marc · 2007-03-27 09:25 The debugger doesn't need to know those. Once a location in code is reached, the debugger reports the file and line number. The IDE resolves this. However it is known that the IDE has sometimes problems with finding include files ---------------------------------------------------------------------- bram · 2007-05-02 08:02 TODBCConnection.UpdateIndexDefs has not been implemented yet, so I guess SQLdb can't process the Post calls yet. (as it doe not know about which key to use in the WHERE clause) Fortunately, I have a patch here which does implement TODBCConnection.UpdateIndexDefs! I will submit it within several days, after testing.