View Issue Details

IDProjectCategoryView StatusLast Update
0031631LazarusLCLpublic2017-05-15 22:48
ReporterSonerAssigned ToJesus Reyes 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformi386-win32OSWindowsOS Version7
Product Version1.6.4Product BuildSVN-REvision: 54278 
Target Version1.8Fixed in Version1.7 (SVN) 
Summary0031631: TDBGrid: (dgMultiSelect in Options) and (not DataSet.Active) and LeftMouseDown = Exception
DescriptionIf the TDBGrid has the option dgMultiselect and the Dataset of the DBGrid closed and the user clicks on mouse button then exception "Dataset Inactive" raises.

Caused by this function:

procedure TCustomDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
//...
          else begin
            if Button=mbLeft then
              ClearSelection(true); // <-- HERE !!!!!
            if gz=gzFixedRows then
//...
            if Button=mbLeft then
              ClearSelection(true); // <-- HERE !!!!!
            doMoveToColumn;
//...
end;


Solution:

procedure TCustomDBGrid.ClearSelection(selCurrent:boolean=false);
begin
  if [dgMultiSelect,dgPersistentMultiSelect]*Options=[dgMultiSelect] then begin
    //..
    if SelCurrent and FDatalink.Active then // ADD HERE : and FDatalink.Active
      SelectRecord(true);
 //..
end;
Steps To Reproduce1. Create new application
2. put TDbGrid on the form.
 select dgMultiSelect from TDbGrid.Options

3. put TDBf or other dataset you don't need any database
4. put TDataSource on the form
5. connect dbf, datasource with Dbgrid
6. Don't open database!
7. run the application and click somewhere in the dbgrid
Additional InformationI added solution in the description.
TagsNo tags attached.
Fixed in Revision54520
LazTarget1.8
WidgetsetWin32/Win64
Attached Files
  • dbgrids.pas.patch (475 bytes)
    Index: lcl/dbgrids.pas
    ===================================================================
    --- lcl/dbgrids.pas	(revision 54507)
    +++ lcl/dbgrids.pas	(working copy)
    @@ -3039,7 +3039,7 @@
     
     function TCustomDBGrid.MouseButtonAllowed(Button: TMouseButton): boolean;
     begin
    -  Result:= (Button=mbLeft) or (dgAnyButtonCanSelect in Options);
    +  Result:= FDataLink.Active and ((Button=mbLeft) or (dgAnyButtonCanSelect in Options));
     end;
     
     procedure TCustomDBGrid.DrawAllRows;
    
    dbgrids.pas.patch (475 bytes)

Activities

Michl

2017-04-04 10:52

developer   ~0099353

I'm not sure, if the changing of the current behaviour is better or not. The exception is clear: "Dataset Inactive".

As developer you can catch the exception and ask the user to connect to the database or give a hint, before he can do it again.

Btw. that isn't only one situation, where this exception is called. E.g. with/without dgMultiSelect in Options, you get the exception with <Ctrl> + Click. If the current behaviour has to be changed, imho the check should be done in TCustomDBGrid.MouseButtonAllowed (see added patch). But I'm not sure, if the current behaviour isn't the better one?!

Michl

2017-04-04 10:52

developer  

dbgrids.pas.patch (475 bytes)
Index: lcl/dbgrids.pas
===================================================================
--- lcl/dbgrids.pas	(revision 54507)
+++ lcl/dbgrids.pas	(working copy)
@@ -3039,7 +3039,7 @@
 
 function TCustomDBGrid.MouseButtonAllowed(Button: TMouseButton): boolean;
 begin
-  Result:= (Button=mbLeft) or (dgAnyButtonCanSelect in Options);
+  Result:= FDataLink.Active and ((Button=mbLeft) or (dgAnyButtonCanSelect in Options));
 end;
 
 procedure TCustomDBGrid.DrawAllRows;
dbgrids.pas.patch (475 bytes)

Soner

2017-04-04 18:04

reporter   ~0099368

I think it is a bug.
There is nothing to clear here, because it is nothing selected (Selcurrent must be false) the dataset is not opened.

Your solution is also good. Maybe it is better to avoid another errors, make it.

Bart Broersma

2017-04-04 18:48

developer   ~0099369

How does Delphi behave in this case?

wp

2017-04-04 20:00

developer   ~0099372

No exception in Delphi 7.

Jesus Reyes

2017-04-04 22:50

developer   ~0099376

Patch applied, thank you.

Issue History

Date Modified Username Field Change
2017-04-04 00:09 Soner New Issue
2017-04-04 10:52 Michl Note Added: 0099353
2017-04-04 10:52 Michl File Added: dbgrids.pas.patch
2017-04-04 18:04 Soner Note Added: 0099368
2017-04-04 18:48 Bart Broersma Note Added: 0099369
2017-04-04 20:00 wp Note Added: 0099372
2017-04-04 22:40 Jesus Reyes Assigned To => Jesus Reyes
2017-04-04 22:40 Jesus Reyes Status new => assigned
2017-04-04 22:50 Jesus Reyes Fixed in Revision => 54520
2017-04-04 22:50 Jesus Reyes LazTarget => 1.8
2017-04-04 22:50 Jesus Reyes Note Added: 0099376
2017-04-04 22:50 Jesus Reyes Status assigned => resolved
2017-04-04 22:50 Jesus Reyes Fixed in Version => 1.7 (SVN)
2017-04-04 22:50 Jesus Reyes Resolution open => fixed
2017-04-04 22:50 Jesus Reyes Target Version => 1.8
2017-05-15 22:48 Soner Status resolved => closed