You've already forked lazarus-ccr
Refactoring. Fixing: update to latest grid changes. Scale using half up
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3058 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -189,6 +189,7 @@ begin
|
|||||||
ftString:
|
ftString:
|
||||||
Result := stringDbGridControl.Editor(Self, Columns[Column - 1].MaxLength);
|
Result := stringDbGridControl.Editor(Self, Columns[Column - 1].MaxLength);
|
||||||
end;
|
end;
|
||||||
|
Result.Visible := False;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -203,12 +204,12 @@ end;
|
|||||||
procedure TJDBGridControl.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
procedure TJDBGridControl.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
||||||
X, Y: integer);
|
X, Y: integer);
|
||||||
begin
|
begin
|
||||||
if integerDbGridControl.CanDefocus and doubleDbGridControl.CanDefocus and
|
if not (integerDbGridControl.CanDefocus and doubleDbGridControl.CanDefocus and
|
||||||
dateTimeDbGridControl.CanDefocus and stringDbGridControl.CanDefocus and
|
dateTimeDbGridControl.CanDefocus and stringDbGridControl.CanDefocus and
|
||||||
dateDbGridControl.CanDefocus and timeDbGridControl.CanDefocus then
|
dateDbGridControl.CanDefocus and timeDbGridControl.CanDefocus) then
|
||||||
inherited MouseDown(Button, Shift, X, Y)
|
abort
|
||||||
else
|
else
|
||||||
abort;
|
inherited MouseDown(Button, Shift, X, Y);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJDBGridControl.KeyDown(var Key: word; Shift: TShiftState);
|
procedure TJDBGridControl.KeyDown(var Key: word; Shift: TShiftState);
|
||||||
|
@ -36,8 +36,8 @@ type
|
|||||||
Field: TField;
|
Field: TField;
|
||||||
updated: boolean;
|
updated: boolean;
|
||||||
fMaxLength: integer;
|
fMaxLength: integer;
|
||||||
EditingFieldNo: LongInt;
|
EditingFieldNo: longint;
|
||||||
EditingRecNo: LongInt;
|
EditingRecNo: longint;
|
||||||
procedure myEditEnter(Sender: TObject);
|
procedure myEditEnter(Sender: TObject);
|
||||||
procedure myEditOnEditingDone(Sender: TObject);
|
procedure myEditOnEditingDone(Sender: TObject);
|
||||||
procedure OnKeyPress(Sender: TObject; var key: char);
|
procedure OnKeyPress(Sender: TObject; var key: char);
|
||||||
@ -59,8 +59,8 @@ type
|
|||||||
updated: boolean;
|
updated: boolean;
|
||||||
theValue: TDateTime;
|
theValue: TDateTime;
|
||||||
fFormat: string;
|
fFormat: string;
|
||||||
EditingFieldNo: LongInt;
|
EditingFieldNo: longint;
|
||||||
EditingRecNo: LongInt;
|
EditingRecNo: longint;
|
||||||
function getFormat: string;
|
function getFormat: string;
|
||||||
function EditText: string;
|
function EditText: string;
|
||||||
procedure myEditEnter(Sender: TObject);
|
procedure myEditEnter(Sender: TObject);
|
||||||
@ -91,8 +91,8 @@ type
|
|||||||
updated: boolean;
|
updated: boolean;
|
||||||
theValue: TTime;
|
theValue: TTime;
|
||||||
fFormat: string;
|
fFormat: string;
|
||||||
EditingFieldNo: LongInt;
|
EditingFieldNo: longint;
|
||||||
EditingRecNo: LongInt;
|
EditingRecNo: longint;
|
||||||
function getFormat: string;
|
function getFormat: string;
|
||||||
procedure myEditEnter(Sender: TObject);
|
procedure myEditEnter(Sender: TObject);
|
||||||
procedure myEditOnEditingDone(Sender: TObject);
|
procedure myEditOnEditingDone(Sender: TObject);
|
||||||
@ -119,8 +119,8 @@ type
|
|||||||
updated: boolean;
|
updated: boolean;
|
||||||
theValue: TDateTime;
|
theValue: TDateTime;
|
||||||
fFormat: string;
|
fFormat: string;
|
||||||
EditingFieldNo: LongInt;
|
EditingFieldNo: longint;
|
||||||
EditingRecNo: LongInt;
|
EditingRecNo: longint;
|
||||||
function getFormat: string;
|
function getFormat: string;
|
||||||
procedure myEditEnter(Sender: TObject);
|
procedure myEditEnter(Sender: TObject);
|
||||||
procedure myEditOnEditingDone(Sender: TObject);
|
procedure myEditOnEditingDone(Sender: TObject);
|
||||||
@ -149,8 +149,8 @@ type
|
|||||||
theValue: integer;
|
theValue: integer;
|
||||||
updated: boolean;
|
updated: boolean;
|
||||||
Field: TField;
|
Field: TField;
|
||||||
EditingFieldNo: LongInt;
|
EditingFieldNo: longint;
|
||||||
EditingRecNo: LongInt;
|
EditingRecNo: longint;
|
||||||
procedure myEditOnEnter(Sender: TObject);
|
procedure myEditOnEnter(Sender: TObject);
|
||||||
procedure OnKeyPress(Sender: TObject; var key: char);
|
procedure OnKeyPress(Sender: TObject; var key: char);
|
||||||
procedure OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
|
procedure OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
|
||||||
@ -174,8 +174,8 @@ type
|
|||||||
theValue: double;
|
theValue: double;
|
||||||
fDecimals: integer;
|
fDecimals: integer;
|
||||||
fEFormat: string;
|
fEFormat: string;
|
||||||
EditingFieldNo: LongInt;
|
EditingFieldNo: longint;
|
||||||
EditingRecNo: LongInt;
|
EditingRecNo: longint;
|
||||||
function getDecimals: integer;
|
function getDecimals: integer;
|
||||||
procedure myEditOnEnter(Sender: TObject);
|
procedure myEditOnEnter(Sender: TObject);
|
||||||
procedure myEditOnEditingDone(Sender: TObject);
|
procedure myEditOnEditingDone(Sender: TObject);
|
||||||
@ -215,8 +215,8 @@ begin
|
|||||||
CellEditor.MaxLength := fMaxLength;
|
CellEditor.MaxLength := fMaxLength;
|
||||||
updated := False;
|
updated := False;
|
||||||
CellEditor.SelectAll;
|
CellEditor.SelectAll;
|
||||||
EditingFieldNo:= Field.FieldNo;
|
EditingFieldNo := Field.FieldNo;
|
||||||
EditingRecNo:= Field.DataSet.RecNo;
|
EditingRecNo := Field.DataSet.RecNo;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJDbGridStringCtrl.myEditOnEditingDone(Sender: TObject);
|
procedure TJDbGridStringCtrl.myEditOnEditingDone(Sender: TObject);
|
||||||
@ -292,7 +292,6 @@ end;
|
|||||||
|
|
||||||
function TJDbGridStringCtrl.CanDefocus: boolean;
|
function TJDbGridStringCtrl.CanDefocus: boolean;
|
||||||
begin
|
begin
|
||||||
CellEditor.Visible := False;
|
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -324,8 +323,8 @@ begin
|
|||||||
theValue := Field.AsDateTime;
|
theValue := Field.AsDateTime;
|
||||||
updated := False;
|
updated := False;
|
||||||
CellEditor.SelectAll;
|
CellEditor.SelectAll;
|
||||||
EditingFieldNo:= Field.FieldNo;
|
EditingFieldNo := Field.FieldNo;
|
||||||
EditingRecNo:= Field.DataSet.RecNo;
|
EditingRecNo := Field.DataSet.RecNo;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJDbGridDateTimeCtrl.myEditOnEditingDone(Sender: TObject);
|
procedure TJDbGridDateTimeCtrl.myEditOnEditingDone(Sender: TObject);
|
||||||
@ -521,21 +520,17 @@ end;
|
|||||||
|
|
||||||
function TJDbGridDateTimeCtrl.CanDefocus: boolean;
|
function TJDbGridDateTimeCtrl.CanDefocus: boolean;
|
||||||
begin
|
begin
|
||||||
if not updated then
|
|
||||||
Result := True
|
|
||||||
else
|
|
||||||
if CellEditor.Focused and (Length(CellEditor.Text) = 0) then
|
|
||||||
Result := True
|
|
||||||
else
|
|
||||||
if CellEditor.Focused and not
|
|
||||||
(IsValidDateTimeString(NormalizeDateTime(CellEditor.Caption, theValue))) then
|
|
||||||
Result := False
|
|
||||||
else
|
|
||||||
Result := True;
|
Result := True;
|
||||||
|
if not CellEditor.Focused then
|
||||||
|
exit;
|
||||||
|
if (Length(CellEditor.Text) = 0) then
|
||||||
|
exit;
|
||||||
|
Result := IsValidDateTimeString(NormalizeDateTime(CellEditor.Caption, theValue));
|
||||||
if not Result then
|
if not Result then
|
||||||
ShowMessage(Format(SInvalidDateTime, [CellEditor.Text]))
|
begin
|
||||||
else
|
ShowMessage(Format(SInvalidDateTime, [CellEditor.Text]));
|
||||||
CellEditor.Visible := False;
|
CellEditor.Text := EditText;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJDbGridTimeCtrl }
|
{ TJDbGridTimeCtrl }
|
||||||
@ -557,8 +552,8 @@ begin
|
|||||||
theValue := Field.AsDateTime;
|
theValue := Field.AsDateTime;
|
||||||
updated := False;
|
updated := False;
|
||||||
CellEditor.SelectAll;
|
CellEditor.SelectAll;
|
||||||
EditingFieldNo:= Field.FieldNo;
|
EditingFieldNo := Field.FieldNo;
|
||||||
EditingRecNo:= Field.DataSet.RecNo;
|
EditingRecNo := Field.DataSet.RecNo;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJDbGridTimeCtrl.myEditOnEditingDone(Sender: TObject);
|
procedure TJDbGridTimeCtrl.myEditOnEditingDone(Sender: TObject);
|
||||||
@ -715,21 +710,17 @@ end;
|
|||||||
|
|
||||||
function TJDbGridTimeCtrl.CanDefocus: boolean;
|
function TJDbGridTimeCtrl.CanDefocus: boolean;
|
||||||
begin
|
begin
|
||||||
if not updated then
|
|
||||||
Result := True
|
|
||||||
else
|
|
||||||
if CellEditor.Focused and (Length(CellEditor.Text) = 0) then
|
|
||||||
Result := True
|
|
||||||
else
|
|
||||||
if CellEditor.Focused and not
|
|
||||||
(IsValidTimeString(NormalizeTime(CellEditor.Caption, theValue))) then
|
|
||||||
Result := False
|
|
||||||
else
|
|
||||||
Result := True;
|
Result := True;
|
||||||
|
if not CellEditor.Focused then
|
||||||
|
exit;
|
||||||
|
if (Length(CellEditor.Text) = 0) then
|
||||||
|
exit;
|
||||||
|
Result := IsValidDateTimeString(NormalizeTime(CellEditor.Caption, theValue));
|
||||||
if not Result then
|
if not Result then
|
||||||
ShowMessage(Format(SInvalidTime, [CellEditor.Text]))
|
begin
|
||||||
else
|
ShowMessage(Format(SInvalidTime, [CellEditor.Text]));
|
||||||
CellEditor.Visible := False;
|
CellEditor.Text := Field.AsString;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJDbGridDateCtrl }
|
{ TJDbGridDateCtrl }
|
||||||
@ -751,8 +742,8 @@ begin
|
|||||||
theValue := Field.AsDateTime;
|
theValue := Field.AsDateTime;
|
||||||
updated := False;
|
updated := False;
|
||||||
CellEditor.SelectAll;
|
CellEditor.SelectAll;
|
||||||
EditingFieldNo:= Field.FieldNo;
|
EditingFieldNo := Field.FieldNo;
|
||||||
EditingRecNo:= Field.DataSet.RecNo;
|
EditingRecNo := Field.DataSet.RecNo;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJDbGridDateCtrl.myEditOnEditingDone(Sender: TObject);
|
procedure TJDbGridDateCtrl.myEditOnEditingDone(Sender: TObject);
|
||||||
@ -948,21 +939,17 @@ end;
|
|||||||
|
|
||||||
function TJDbGridDateCtrl.CanDefocus: boolean;
|
function TJDbGridDateCtrl.CanDefocus: boolean;
|
||||||
begin
|
begin
|
||||||
if not updated then
|
|
||||||
Result := True
|
|
||||||
else
|
|
||||||
if CellEditor.Focused and (Length(CellEditor.Text) = 0) then
|
|
||||||
Result := True
|
|
||||||
else
|
|
||||||
if CellEditor.Focused and not
|
|
||||||
(IsValidDateTimeString(NormalizeDateTime(CellEditor.Caption, theValue))) then
|
|
||||||
Result := False
|
|
||||||
else
|
|
||||||
Result := True;
|
Result := True;
|
||||||
|
if not CellEditor.Focused then
|
||||||
|
exit;
|
||||||
|
if (Length(CellEditor.Text) = 0) then
|
||||||
|
exit;
|
||||||
|
Result := IsValidDateTimeString(NormalizeDateTime(CellEditor.Caption, theValue));
|
||||||
if not Result then
|
if not Result then
|
||||||
ShowMessage(Format(SInvalidDate, [CellEditor.Text]))
|
begin
|
||||||
else
|
ShowMessage(Format(SInvalidDate, [CellEditor.Text]));
|
||||||
CellEditor.Visible := False;
|
CellEditor.Text := Field.AsString;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJDbGridDoubleCtrl }
|
{ TJDbGridDoubleCtrl }
|
||||||
@ -987,8 +974,8 @@ begin
|
|||||||
theValue := Field.AsFloat;
|
theValue := Field.AsFloat;
|
||||||
updated := False;
|
updated := False;
|
||||||
CellEditor.SelectAll;
|
CellEditor.SelectAll;
|
||||||
EditingFieldNo:= Field.FieldNo;
|
EditingFieldNo := Field.FieldNo;
|
||||||
EditingRecNo:= Field.DataSet.RecNo;
|
EditingRecNo := Field.DataSet.RecNo;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJDbGridDoubleCtrl.myEditOnEditingDone(Sender: TObject);
|
procedure TJDbGridDoubleCtrl.myEditOnEditingDone(Sender: TObject);
|
||||||
@ -1091,7 +1078,11 @@ end;
|
|||||||
function TJDbGridDoubleCtrl.ScaleTo(const AValue: double;
|
function TJDbGridDoubleCtrl.ScaleTo(const AValue: double;
|
||||||
const NDecimals: integer): double;
|
const NDecimals: integer): double;
|
||||||
begin
|
begin
|
||||||
Result := round(AValue * power(10, NDecimals)) / power(10, NDecimals);
|
// rounding halfup
|
||||||
|
if AValue > 0 then
|
||||||
|
Result := trunc(AValue * power(10, NDecimals) + 0.5) / power(10, NDecimals)
|
||||||
|
else
|
||||||
|
Result := trunc(AValue * power(10, NDecimals) - 0.5) / power(10, NDecimals);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TJDbGridDoubleCtrl.Create;
|
constructor TJDbGridDoubleCtrl.Create;
|
||||||
@ -1121,14 +1112,18 @@ end;
|
|||||||
|
|
||||||
function TJDbGridDoubleCtrl.CanDefocus: boolean;
|
function TJDbGridDoubleCtrl.CanDefocus: boolean;
|
||||||
begin
|
begin
|
||||||
if CellEditor.Focused then
|
|
||||||
Result := IsValidFloat(CellEditor.Text)
|
|
||||||
else
|
|
||||||
Result := True;
|
Result := True;
|
||||||
|
if not CellEditor.Focused then
|
||||||
|
exit;
|
||||||
|
Result := IsValidFloat(CellEditor.Text);
|
||||||
if not Result then
|
if not Result then
|
||||||
ShowMessage(Format(SInvalidNumber, [CellEditor.Text]))
|
begin
|
||||||
|
ShowMessage(Format(SInvalidNumber, [CellEditor.Text]));
|
||||||
|
if Length(fEFormat) > 0 then
|
||||||
|
CellEditor.Text := FormatFloat(fEFormat, Field.AsFloat)
|
||||||
else
|
else
|
||||||
CellEditor.Visible := False;
|
CellEditor.Text := Field.AsString;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TJDbGridIntegerCtrl }
|
{ TJDbGridIntegerCtrl }
|
||||||
@ -1143,8 +1138,8 @@ begin
|
|||||||
theValue := Field.AsInteger;
|
theValue := Field.AsInteger;
|
||||||
CellEditor.SelectAll;
|
CellEditor.SelectAll;
|
||||||
updated := False;
|
updated := False;
|
||||||
EditingFieldNo:= Field.FieldNo;
|
EditingFieldNo := Field.FieldNo;
|
||||||
EditingRecNo:= Field.DataSet.RecNo;
|
EditingRecNo := Field.DataSet.RecNo;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TJDbGridIntegerCtrl.OnKeyPress(Sender: TObject; var key: char);
|
procedure TJDbGridIntegerCtrl.OnKeyPress(Sender: TObject; var key: char);
|
||||||
@ -1252,14 +1247,15 @@ end;
|
|||||||
|
|
||||||
function TJDbGridIntegerCtrl.CanDefocus: boolean;
|
function TJDbGridIntegerCtrl.CanDefocus: boolean;
|
||||||
begin
|
begin
|
||||||
if CellEditor.Focused then
|
|
||||||
Result := IsValidInteger(CellEditor.Text)
|
|
||||||
else
|
|
||||||
Result := True;
|
Result := True;
|
||||||
|
if not CellEditor.Focused then
|
||||||
|
exit;
|
||||||
|
Result := IsValidInteger(CellEditor.Text);
|
||||||
if not Result then
|
if not Result then
|
||||||
ShowMessage(Format(SInvalidNumber, [CellEditor.Text]))
|
begin
|
||||||
else
|
ShowMessage(Format(SInvalidNumber, [CellEditor.Text]));
|
||||||
CellEditor.Visible := False;
|
CellEditor.Text := Field.AsString;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Reference in New Issue
Block a user