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:
jujibo
2014-05-19 09:27:09 +00:00
parent c5ab6d6ddc
commit 44a02408aa
2 changed files with 82 additions and 85 deletions

View File

@ -189,6 +189,7 @@ begin
ftString:
Result := stringDbGridControl.Editor(Self, Columns[Column - 1].MaxLength);
end;
Result.Visible := False;
end;
end;
end;
@ -203,12 +204,12 @@ end;
procedure TJDBGridControl.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: integer);
begin
if integerDbGridControl.CanDefocus and doubleDbGridControl.CanDefocus and
if not (integerDbGridControl.CanDefocus and doubleDbGridControl.CanDefocus and
dateTimeDbGridControl.CanDefocus and stringDbGridControl.CanDefocus and
dateDbGridControl.CanDefocus and timeDbGridControl.CanDefocus then
inherited MouseDown(Button, Shift, X, Y)
dateDbGridControl.CanDefocus and timeDbGridControl.CanDefocus) then
abort
else
abort;
inherited MouseDown(Button, Shift, X, Y);
end;
procedure TJDBGridControl.KeyDown(var Key: word; Shift: TShiftState);

View File

@ -36,8 +36,8 @@ type
Field: TField;
updated: boolean;
fMaxLength: integer;
EditingFieldNo: LongInt;
EditingRecNo: LongInt;
EditingFieldNo: longint;
EditingRecNo: longint;
procedure myEditEnter(Sender: TObject);
procedure myEditOnEditingDone(Sender: TObject);
procedure OnKeyPress(Sender: TObject; var key: char);
@ -59,8 +59,8 @@ type
updated: boolean;
theValue: TDateTime;
fFormat: string;
EditingFieldNo: LongInt;
EditingRecNo: LongInt;
EditingFieldNo: longint;
EditingRecNo: longint;
function getFormat: string;
function EditText: string;
procedure myEditEnter(Sender: TObject);
@ -91,8 +91,8 @@ type
updated: boolean;
theValue: TTime;
fFormat: string;
EditingFieldNo: LongInt;
EditingRecNo: LongInt;
EditingFieldNo: longint;
EditingRecNo: longint;
function getFormat: string;
procedure myEditEnter(Sender: TObject);
procedure myEditOnEditingDone(Sender: TObject);
@ -119,8 +119,8 @@ type
updated: boolean;
theValue: TDateTime;
fFormat: string;
EditingFieldNo: LongInt;
EditingRecNo: LongInt;
EditingFieldNo: longint;
EditingRecNo: longint;
function getFormat: string;
procedure myEditEnter(Sender: TObject);
procedure myEditOnEditingDone(Sender: TObject);
@ -149,8 +149,8 @@ type
theValue: integer;
updated: boolean;
Field: TField;
EditingFieldNo: LongInt;
EditingRecNo: LongInt;
EditingFieldNo: longint;
EditingRecNo: longint;
procedure myEditOnEnter(Sender: TObject);
procedure OnKeyPress(Sender: TObject; var key: char);
procedure OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
@ -174,8 +174,8 @@ type
theValue: double;
fDecimals: integer;
fEFormat: string;
EditingFieldNo: LongInt;
EditingRecNo: LongInt;
EditingFieldNo: longint;
EditingRecNo: longint;
function getDecimals: integer;
procedure myEditOnEnter(Sender: TObject);
procedure myEditOnEditingDone(Sender: TObject);
@ -292,7 +292,6 @@ end;
function TJDbGridStringCtrl.CanDefocus: boolean;
begin
CellEditor.Visible := False;
Result := True;
end;
@ -521,21 +520,17 @@ end;
function TJDbGridDateTimeCtrl.CanDefocus: boolean;
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;
if not CellEditor.Focused then
exit;
if (Length(CellEditor.Text) = 0) then
exit;
Result := IsValidDateTimeString(NormalizeDateTime(CellEditor.Caption, theValue));
if not Result then
ShowMessage(Format(SInvalidDateTime, [CellEditor.Text]))
else
CellEditor.Visible := False;
begin
ShowMessage(Format(SInvalidDateTime, [CellEditor.Text]));
CellEditor.Text := EditText;
end;
end;
{ TJDbGridTimeCtrl }
@ -715,21 +710,17 @@ end;
function TJDbGridTimeCtrl.CanDefocus: boolean;
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;
if not CellEditor.Focused then
exit;
if (Length(CellEditor.Text) = 0) then
exit;
Result := IsValidDateTimeString(NormalizeTime(CellEditor.Caption, theValue));
if not Result then
ShowMessage(Format(SInvalidTime, [CellEditor.Text]))
else
CellEditor.Visible := False;
begin
ShowMessage(Format(SInvalidTime, [CellEditor.Text]));
CellEditor.Text := Field.AsString;
end;
end;
{ TJDbGridDateCtrl }
@ -948,21 +939,17 @@ end;
function TJDbGridDateCtrl.CanDefocus: boolean;
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;
if not CellEditor.Focused then
exit;
if (Length(CellEditor.Text) = 0) then
exit;
Result := IsValidDateTimeString(NormalizeDateTime(CellEditor.Caption, theValue));
if not Result then
ShowMessage(Format(SInvalidDate, [CellEditor.Text]))
else
CellEditor.Visible := False;
begin
ShowMessage(Format(SInvalidDate, [CellEditor.Text]));
CellEditor.Text := Field.AsString;
end;
end;
{ TJDbGridDoubleCtrl }
@ -1091,7 +1078,11 @@ end;
function TJDbGridDoubleCtrl.ScaleTo(const AValue: double;
const NDecimals: integer): double;
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;
constructor TJDbGridDoubleCtrl.Create;
@ -1121,14 +1112,18 @@ end;
function TJDbGridDoubleCtrl.CanDefocus: boolean;
begin
if CellEditor.Focused then
Result := IsValidFloat(CellEditor.Text)
else
Result := True;
if not CellEditor.Focused then
exit;
Result := IsValidFloat(CellEditor.Text);
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
CellEditor.Visible := False;
CellEditor.Text := Field.AsString;
end;
end;
{ TJDbGridIntegerCtrl }
@ -1252,14 +1247,15 @@ end;
function TJDbGridIntegerCtrl.CanDefocus: boolean;
begin
if CellEditor.Focused then
Result := IsValidInteger(CellEditor.Text)
else
Result := True;
if not CellEditor.Focused then
exit;
Result := IsValidInteger(CellEditor.Text);
if not Result then
ShowMessage(Format(SInvalidNumber, [CellEditor.Text]))
else
CellEditor.Visible := False;
begin
ShowMessage(Format(SInvalidNumber, [CellEditor.Text]));
CellEditor.Text := Field.AsString;
end;
end;
end.