The DBGrid's field is filled with garbage when the focus is changed to another field.
Original Reporter info from Mantis: Samus
-
Reporter name: Paulo Sérgio
Original Reporter info from Mantis: Samus
- Reporter name: Paulo Sérgio
Description:
In the form, I added a BufDataset connected to DBGrid.
My code:
procedure TForm1.FormCreate(Sender: TObject);
begin
BufDataset1.FieldDefs.Add('Field1', ftString, 10);
BufDataset1.FieldDefs.Add('Field2', ftString, 10);
BufDataset1.CreateDataset;
BufDataset1.AppendRecord(['aaaaaaaaaa', 'bbbbbbbbbb']);
BufDataset1.AppendRecord(['cccccccccc', 'dddddddddd']);
end;
Steps to reproduce:
Steps:
1 - Run the Program.
2 - Click in first field of the first record.
3 - Put the field in edit mode and position the caret at the end of the text.
4 - Type anything.
5 - Click on another field.
6 - The first field is empty. And the previous text is lost.
Another way to cause the bug.
Steps:
1 - Run the Program.
2 - Click in second field of the first record.
3 - Typing, replace text for "12345".
4 - Click in first field of the first record.
5 - Put the field in edit mode and position the caret at the end of the text.
6 - Type anything.
7 - Click on another field.
6 - The text of the first field is changed to "12345". And the previous text is lost.
Additional information:
The bug occurs because of the field FTempText in the class TCustomDBGrid.
To solve the problem I did this:
function TCustomDBGrid.GetEditText(aCol, aRow: Longint): string;
var
aField: TField;
begin
Result := '';
if FDataLink.Active then begin
aField := GetFieldFromGridColumn(aCol);
if aField<>nil then begin
if CheckDisplayMemo(aField) then
Result := aField.AsString
else
Result := aField.Text;
end;
end;
FTempText := Result; //<------- Solve the problem
end;
Tested in Lazarus versions: 1.8.0, 1.8.2 and 1.9.0
Mantis conversion info:
- Mantis ID: 33734
- OS: Windows
- OS Build: 10
- Platform: Desktop
- Version: 1.9 (SVN)
- Fixed in version: 1.9 (SVN)
- Fixed in revision: 58010 (#de467a09)