Hello,
I am using TSringGrid To get the run parameters from the user. The user input is limited and validated depending on the value in the left cell (aCol-1) . A possible input is a string witch has to be converted to a real. If the string is not convertible the user gets a message and a standard value is placed in the cell. On top of it I would like to have the focus in the cell witch has to be corrected. I always end up in the next cell (aCol+1)
The problem code is in the Validate entry procedure in the except part of the try statement. The commented out lines (//) d'ont help or make things worse (like a never ending loop)
Lazarus : 0.9.30
fpc : 2.4.2
xpsp3
anyone suggestions?
procedure TForm1.EventTableSelectEditor(Sender: TObject; aCol, aRow: Integer;
var Editor: TWinControl);
var
dozin:string;
begin
with Editor as TCustomComboBox do begin
case aCol of
1:begin
Style := csDropDownList ;
end;
2:begin
dozin := EventTable.Cells[aCol-1,arow];
case StringCase(dozin,['AtOnce', 'EventTime', 'RunTime', 'WaitFor', 'WaitForUntil']) of
0:begin
Style := csDropDownList ;
Items.CommaText:= 'none';
end;
1: Editor := EventTable.EditorByStyle(cbsEllipsis);
2: Editor := EventTable.EditorByStyle(cbsEllipsis);
3,4:begin
Style := csDropDownList ;
Items.CommaText:= '1,2,3,4,5';
end;
end; // end case evzin
end;
3:begin
Style := csDropDownList ;
end;
4:begin
end;
end; //end case aCol
end; //end with as do
end;
procedure TForm1.EventTableValidateEntry(sender: TObject; aCol, aRow: Integer;
const OldValue: string; var NewValue: String);
var
dozin:string;
retint:extended;
msgstr:string;
begin
dozin := EventTable.Cells[aCol-1,aRow];
vFlag := true;
case aCol of
1,3: if OldValue <> NewValue then EventTable.cells[aCol+1,aRow]:= '';
2: begin
case StringCase(dozin,['AtOnce', 'EventTime', 'RunTime', 'WaitFor', 'WaitForUntil']) of
1,2:begin
Try
NewValue := FloatToStrF(StrToFloat(Newvalue),ffFixed,1,3)
except
on E : exception do
begin
vFlag := false;
vCol := aCol;
vRow := aRow;
ShowMessage(E.Message + ' ' + NewValue);
//EventTable.AutoAdvance := aanone;
EventTable.Cells[aCol,aRow]:='0,0';
//NewValue:='1,1';
EventTable.Row:=aRow; // here it goes wrong
EventTable.Col:=aCol;
EventTable.SetFocus;
end;
end;
end;
4: ;//validate non picklist vallues;
end;
end;
end;
end;