View Issue Details

IDProjectCategoryView StatusLast Update
0022804LazarusLCLpublic2012-09-06 07:11
ReporterStefano Assigned ToJesus Reyes  
PrioritynormalSeveritymajorReproducibilityalways
Status assignedResolutionopen 
Product Version1.0.0 
Summary0022804: DBGrid lost focus when moving into the dataset
DescriptionHello,

Since Lazarus 0.9.30 and next versions (0.9.30.2, 0.9.30.4, 1.0) I've noted that sometimes the DbGrid lost focus (Bug 0019993).

Now I've believe to have found the cause of the problem: the problem occours when moving into the record of the dataset associeted to the dbgrid (for example to calculate totals of a currency field).

If in the OnKeyDown event I wish calculate the totals of the dbgrid (if the keys are Key of deplacement (Arrows, PgUp, PdDown, Tab, ...)) and call a calcprocedure, the grid lost focus.

When the grid lost focus, it occours the problem (at run time) in case of moving between forms/windows with Alt + Tab (Bug 0022475). This is a great problem.

If I put a setfocus command after the calcprocedure, it seems to work until the user don't move on the form with Alt+Tab. After that, when the dbgrid cause the calc procedure lost focus, there are problems in inserting data in the cells, a charachter replace the previous.

I use Linux (Debian Squeeze) with GTK2.

Best regards,

Stefano
Additional Informationprocedure TForm2.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

[...]

  //Lazarus 1.0: THIS CODE GIVE PROBLEMS WITH ALT+TAB
  if (Key = 38 {KeyArrowUp}) or (Key = 40 {KeyArrowDown}) then begin
    if (dbgrid1.SelectedIndex = 2) then begin
      CalcTotali; //Lazarus 1.0: After that, the grid/cells lost focus!
    end;
  end;

[...]

end;

procedure TForm2.CalcTotali;
var
  Bmk: TBookmark;
  C, MyTot: Currency;
begin
  C := 0;
  MyTot := 0;
  Label1.Caption := '';
  if (SqlQuery1.Active = False) then exit;
  if (SqlQuery1.RecordCount < 1) then exit;

  Bmk := SqlQuery1.GetBookmark;
  try
    if (SqlQuery1.State in [dsEdit, dsInsert]) then SqlQuery1.Post; //Memorizza eventuali modifiche apportate
  except
  end;
  try
    SqlQuery1.DisableControls;
    SqlQuery1.First;
    while not SqlQuery1.EOF do begin
      try
        C := SqlQuery1.FieldByName('FIELD3').AsCurrency;
      except
        C := 0;
      end;
      MyTot := MyTot + C;
      SqlQuery1.Next;
    end;
  finally
    try
      SqlQuery1.GotoBookmark(Bmk);
    except
    end;
    SqlQuery1.EnableControls;
  end;
  Label1.Caption := CurrToStrF(MyTot, ffNumber, 2);
end;

TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetGTK 2
Attached Files

Relationships

related to 0019993 resolvedJesus Reyes Bugs in DbGrid with Lazarus 0.9.30 

Activities

Stefano

2012-09-05 21:35

reporter   ~0062108

The problem seems to concern above all the Currency Fields. When with Alt+Tab the user go to a StringFieldCell, it seems work, but when the user go to a CurrencyFieldCell the problem occours. When the problem occours, after that also StringFieldCell have the problem.

Issue History

Date Modified Username Field Change
2012-09-05 17:55 Stefano New Issue
2012-09-05 17:55 Stefano Widgetset => GTK 2
2012-09-05 21:35 Stefano Note Added: 0062108
2012-09-06 07:11 Jesus Reyes Status new => assigned
2012-09-06 07:11 Jesus Reyes Assigned To => Jesus Reyes
2012-09-22 20:09 Jesus Reyes Relationship added related to 0019993