Preventing double updates (QT widgetset)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2338 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
jujibo
2012-03-14 15:56:06 +00:00
parent 9c3f8d1bfb
commit 69552795e1
4 changed files with 74 additions and 56 deletions

View File

@@ -5,6 +5,7 @@ Note: Lazarus Trunk required
Version pre-1.1
--------------------------------------------------
2012-03-14 Fixed: Prevent double updates (QT widgetset) in edit widgets
2012-03-06 Fixed: Focus issues
Version 1.0

View File

@@ -35,6 +35,7 @@ type
fFormat: string;
FDataLink: TFieldDataLink;
fDecimales: integer;
fUpdated: boolean;
procedure DataChange(Sender: TObject);
function getDecimals: integer;
@@ -174,29 +175,31 @@ procedure TJDBLabeledCurrencyEdit.UpdateData(Sender: TObject);
var
theValue: currency;
begin
if FDataLink.Field <> nil then
begin
if IsValidCurrency(Text) then
if not fUpdated then
if FDataLink.Field <> nil then
begin
theValue := StrToCurr(Text);
if fDecimales > 0 then
theValue := ScaleTo(theValue, fDecimales);
Text := CurrToStr(theValue);
FDataLink.Field.Value := theValue;
if IsValidCurrency(Text) then
begin
theValue := StrToCurr(Text);
if fDecimales > 0 then
theValue := ScaleTo(theValue, fDecimales);
Text := CurrToStr(theValue);
FDataLink.Field.Value := theValue;
fUpdated:= True;
end
else
begin
if FDataLink.Field <> nil then
begin
ShowMessage(Format(SInvalidNumber, [Caption]));
Caption := FDataLink.Field.AsString;
SelectAll;
SetFocus;
end;
end;
end
else
begin
if FDataLink.Field <> nil then
begin
ShowMessage(Format(SInvalidNumber, [Caption]));
Caption := FDataLink.Field.AsString;
SelectAll;
SetFocus;
end;
end;
end
else
Text := '';
Text := '';
end;
procedure TJDBLabeledCurrencyEdit.FocusRequest(Sender: TObject);
@@ -356,13 +359,15 @@ procedure TJDBLabeledCurrencyEdit.DoEnter;
begin
if FDataLink.Field <> nil then
Caption := FDataLink.Field.AsString;
fUpdated:= False;
inherited DoEnter;
end;
procedure TJDBLabeledCurrencyEdit.DoExit;
begin
formatInput;
inherited DoExit;
UpdateData(nil);
formatInput;
end;
constructor TJDBLabeledCurrencyEdit.Create(TheOwner: TComponent);

View File

@@ -35,6 +35,7 @@ type
fFormat: string;
FDataLink: TFieldDataLink;
fDecimales: integer;
fUpdated: boolean;
procedure DataChange(Sender: TObject);
function getDecimals: integer;
@@ -173,29 +174,31 @@ procedure TJDBLabeledFloatEdit.UpdateData(Sender: TObject);
var
theValue: double;
begin
if FDataLink.Field <> nil then
begin
if IsValidFloat(Text) then
if not fUpdated then
if FDataLink.Field <> nil then
begin
theValue := StrToFloat(Text);
if fDecimales > 0 then
theValue := ScaleTo(theValue, fDecimales);
Text := FloatToStr(theValue);
FDataLink.Field.Value := theValue;
if IsValidFloat(Text) then
begin
theValue := StrToFloat(Text);
if fDecimales > 0 then
theValue := ScaleTo(theValue, fDecimales);
Text := FloatToStr(theValue);
FDataLink.Field.Value := theValue;
fUpdated := True;
end
else
begin
if FDataLink.Field <> nil then
begin
ShowMessage(Format(SInvalidNumber, [Caption]));
Caption := FDataLink.Field.AsString;
SelectAll;
SetFocus;
end;
end;
end
else
begin
if FDataLink.Field <> nil then
begin
ShowMessage(Format(SInvalidNumber, [Caption]));
Caption := FDataLink.Field.AsString;
SelectAll;
SetFocus;
end;
end;
end
else
Text := '';
Text := '';
end;
procedure TJDBLabeledFloatEdit.FocusRequest(Sender: TObject);
@@ -354,13 +357,15 @@ procedure TJDBLabeledFloatEdit.DoEnter;
begin
if FDataLink.Field <> nil then
Caption := FDataLink.Field.AsString;
fUpdated := False;
inherited DoEnter;
end;
procedure TJDBLabeledFloatEdit.DoExit;
begin
formatInput;
inherited DoExit;
UpdateData(nil);
formatInput;
end;
constructor TJDBLabeledFloatEdit.Create(TheOwner: TComponent);

View File

@@ -34,6 +34,7 @@ type
private
fFormat: string;
FDataLink: TFieldDataLink;
fUpdated: boolean;
procedure DataChange(Sender: TObject);
procedure UpdateData(Sender: TObject);
@@ -154,20 +155,24 @@ end;
procedure TJDBLabeledIntegerEdit.UpdateData(Sender: TObject);
begin
if FDataLink.Field <> nil then
begin
if IsValidInteger(Caption) then
FDataLink.Field.Text := Text
else
if not fUpdated then
if FDataLink.Field <> nil then
begin
ShowMessage(Format(SInvalidNumber, [Caption]));
Caption := FDataLink.Field.AsString;
SelectAll;
SetFocus;
end;
end
else
Text := '';
if IsValidInteger(Caption) then
begin
FDataLink.Field.Text := Text;
fUpdated:= True
end
else
begin
ShowMessage(Format(SInvalidNumber, [Caption]));
Caption := FDataLink.Field.AsString;
SelectAll;
SetFocus;
end;
end
else
Text := '';
end;
procedure TJDBLabeledIntegerEdit.FocusRequest(Sender: TObject);
@@ -317,13 +322,15 @@ procedure TJDBLabeledIntegerEdit.DoEnter;
begin
if FDataLink.Field <> nil then
Caption := FDataLink.Field.AsString;
fUpdated:= False;
inherited DoEnter;
end;
procedure TJDBLabeledIntegerEdit.DoExit;
begin
formatInput;
inherited DoExit;
UpdateData(nil);
formatInput;
end;
constructor TJDBLabeledIntegerEdit.Create(TheOwner: TComponent);