Recent

Author Topic: [EXAMPLE] DBGrid toggel boolean feild of all item in a BookMark selection  (Read 498 times)

What I can do

  • Full Member
  • ***
  • Posts: 152
OS: Windows 10@64
Compiler: Lazarus 3.8
Project: Multi select rows in a DBGrid and with a give Boolean expression set the boolean field to all the selected rows with the new expression

I have researched ...
Sieben  November 03, 2024
https://forum.lazarus.freepascal.org/index.php/topic,69152.msg536709.html#msg536709

jesusr March 16, 2019
https://forum.lazarus.freepascal.org/index.php/topic,44668.msg314453.html#msg314453

jesusr May 18, 2024
https://forum.lazarus.freepascal.org/index.php/topic,67311.msg517746.html#msg517746

GAN May 17, 2017
https://forum.lazarus.freepascal.org/index.php/topic,36900.0.html?PHPSESSID=b6eemlbvd1gdsp2horkacb8hu7

but something in this code is wrong...

Code: Pascal  [Select][+][-]
  1. procedure TForm1.SpeedButton27Click(Sender: TObject);
  2. var I:integer;
  3.     NewValue: Boolean;
  4. begin
  5.  if ComboBox6.ItemIndex = 0 then
  6.       NewValue := TRUE  // 0 = TRUE
  7.     else if ComboBox6.ItemIndex = 1 then
  8.       NewValue := False; // 1 = FALSE
  9. for i:=0 to DBGrid1.SelectedRows.Count-1 do
  10.   with DBGrid1.DataSource.DataSet do
  11.     begin
  12.       GotoBookmark(pointer(DBGrid1.SelectedRows.Items[i]));
  13.       Edit;
  14.       FieldByName('H_Active').AsBoolean := NewValue;
  15.       Post;
  16.     end;
  17.   end;
  18.  

when I [F8] step through it the first time loop it all works fine at record-0
but on the next loop record-1 it crashes with this error..

[ERROR]
 Project HLP raised exception class 'External: ACCESS
VIOLATION:' with message
Access violation reading address
at address 100003184
« Last Edit: February 02, 2025, 12:33:36 am by What I can do »

What I can do

  • Full Member
  • ***
  • Posts: 152
Up Date 1/31/2025
If you are curious about my DB module settings here is where it is all set

Code: Pascal  [Select][+][-]
  1.   Procedure BuildDBModuals(aFile:TFileName);
  2.   var
  3.     CName:String;
  4.   begin
  5.    Inc(DBn);
  6.    SetLength(DBM,Length(DBM)+1);
  7.    CName:='DBM'+DBn.ToString;
  8.    DBM[DBn].C:=TODBCConnection.Create(DBM[DBn].C);
  9.    DBM[DBn].C.DatabaseName:='Access64';
  10.    DBM[DBn].C.Name:=cName+'Con';
  11.    DoSetupAconn(DBM[DBn].C,aFile);
  12.  
  13.    DBM[DBn].T:=TSQLTransaction.Create(DBM[DBn].T);
  14.    DBM[DBn].T.DataBase:=DBM[DBn].C;
  15.    DBM[DBn].T.Action:=caCommit;
  16.    DBM[DBn].T.Name:=CName+'Trans';
  17.    DoSetupTranaction(DBM[DBn].T,DBM[DBn].C);
  18.  
  19.    DBM[DBn].Q:=TSQLQuery.Create(DBM[DBn].Q);
  20.    DBM[DBn].Q.DataBase:=DBM[DBn].C;
  21.    DBM[DBn].Q.Transaction:=DBM[DBn].T;
  22.    DBM[DBn].Q.Name:=CName+'Query';
  23.    DoSetupSQLQuery(DBM[DBn].Q,DBM[DBn].C);
  24.  
  25.    DBM[DBn].D:=TDataSource.Create(DBM[DBn].D);
  26.    DBM[DBn].D.Dataset:= DBM[DBn].Q;
  27.    DBM[DBn].D.Name:=CName+'Data';
  28.   end;
  29.  

What I can do

  • Full Member
  • ***
  • Posts: 152
Re: [EXAMPLE] DBGrid toggel boolean feild of all item in a BookMark selection
« Reply #2 on: February 02, 2025, 12:48:23 am »
Update 2/1/2025
Errors like this are more difficult to find and many time report after the fact so you have to start with two basic mind sets
1) start where the error occurred and walk event by event backwards to see if some form of error my instigate the exception.
2) also you must strongly retrace to what was the last update before the errors started to occur.
what I found were two major errors that produced exceptions
First I have a panel that works similar to a another form but stays within the launch form window which has features like drag and close top [X]
the problem started after I made some adjustment to the panel height so to automate the results on the bottom of this panel is a DBGrid with anchors on all sides and there is where the hidden error lies because a an additional feature on the panel is to minimize to maximized by which shrinking the panel height from 865 to 86. The now invisible DBGrid is twisted upside down and all crunched up do to the anchors. So release the anchors and that was fixed.

The second exception was a Query.refresh before the loop through the BookMarks was complete. Well ya can't refresh or much db action during a bookmark loop
Now It all works wonderful and YES, all the above code is working smoothly without exception. 

 

TinyPortal © 2005-2018