The following code works nicely with standard TTable but generates an Access violation with a TDAMemDataTable.
Maybe that the Edit/Post alters in some way the TDAMemDataTable.TBookmarkList?
How can I iterate over the SelectedRows of a DBGrid, editing each row during the iteration, without having to use a parameterized DACommand/StoredProcedure?
var Giorno: TDAMemDataTable; ..... Giorno := ClientDataModule.tbl_GIORNO; Giorno.DisableControls; for i := 0 to dbgrd_GIORNO.SelectedRows.Count - 1 do begin Giorno.GoToBookmark(TBookmark(dbgrd_GIORNO.SelectedRows[i])); <=== // Access Violation here! Giorno.Edit; Giorno.FieldByName('GIUSTIFICATIVO_ID').AsLargeInt := 5; Giorno.Post; end; Giorno.EnableControls;
Edit: Problem solved (mea culpa)!
ClientDataModule.tbl_GIORNO has two events wired: BeforePost and AfterPost. These events where fired, as they names suggest, BeforePost and AfterPost, thus messing up the Giorno.GoToBookmark(TBookmark(dbgrd_GIORNO.SelectedRows[i])) statement.
Temporarily setting both the events to Nil (and reassigning them after the updates are done), solved the problem for me.
var i: integer; Giorno: TDAMemDataTable; begin Giorno := ClientDataModule.tbl_GIORNO; Giorno.DisableControls; Giorno.BeforePost := nil; Giorno.AfterPost := nil; Giorno.RemoteUpdatesOptions := Giorno.RemoteUpdatesOptions - [ruoOnPost]; for i := 0 to dbgrd_GIORNO.SelectedRows.Count - 1 do begin Giorno.GoToBookmark(TBookmark(dbgrd_GIORNO.SelectedRows[i])); if (Giorno.FieldByName('ORE_EFFETTIVE_HH_MM').AsCurrency > 0) then begin Giorno.Edit; Giorno.FieldByName('GIUSTIFICATIVO_ID').AsLargeInt := 5; Giorno.Post; end; end; Giorno.ApplyUpdates(False, True); Giorno.RemoteUpdatesOptions := Giorno.RemoteUpdatesOptions + [ruoOnPost]; Giorno.BeforePost := ClientDataModule.tbl_GIORNOBeforePost; Giorno.AfterPost := ClientDataModule.tbl_GIORNOAfterPost; end;
–
fabio vitale