TDBGrid sometimes sets empty string as field value when using a custom editor.
Original Reporter info from Mantis: luca @olivluca
-
Reporter name: Luca Olivetti
Original Reporter info from Mantis: luca @olivluca
- Reporter name: Luca Olivetti
Description:
Depending on how you change cell while editing, if you're using a custom editor the value of the field is reset to the empty string.
Steps to reproduce:
In the attached project scroll down with the keyboard to enter a new record.
Type a number in col1 so that the spinedit appears. Look at the console window that the event is fired and the field is set to the spinedit value.
Then click on col2 and see that the col1 cell is now empty.
If instead of typing you click on col1 and use the arrows in the spinedit the value seems to stick.
Note that the spinedit here is just an example, it happens with other kinds of custom editors.
Additional information:
The problem is that when changing cell, depending on how it changed, it invokes the method
TCustomGrid.MoveExtend
which calls
TCustomGrid.EditorGetValue(true) -> TCustomDBGrid.EditorDoGetValue -> TCustomGrid.EditordoGetValue
which uses this code to update the field value:
if (FEditor<>nil) and FEditor.Visible then begin
Msg.LclMsg.msg:=GM_GETVALUE;
Msg.grid:=Self;
Msg.Col:=FCol;
Msg.Row:=FRow;
Msg.Value:=GetCells(FCol, FRow);
FEditor.Dispatch(Msg);
SetEditText(Msg.Col, Msg.Row, Msg.Value);
end;
The problem is that only the editors defined in Grids.pas manage the GM_GETVALUE message, so when using a custom editor the resulting text is what GetCells returns, which in case of a DBGrid is FTempText and it's empty in the above example.
Mantis conversion info:
- Mantis ID: 28944
- Version: 1.4.4