Reputation: 313
I am creating an Delphi 2007 application, using Tnt components (Compenents with unicode). I have a form with:
edit : TTntEdit;
updown : TTntUpDown
settings for thouse components are:
edit.OnKeyPressed := edKeyPress;
edit.OnKExit := edExit;
updown.Max := 900;
updown.Min := 300;
updown.Assosiate := edit;
updown.onClick := updownClick;
procedure TForm.edKeyPress(Sender: TObject;
var Key: Char);
begin
if Key = #13 then
begin
Key := #0;
SetValue(edit, updown, some_global_variable );
end;
end;
procedure TForm.edExit(Sender: TObject);
begin
SetValue(edit, updown, some_global_variable);
end;
procedure TForm.SetValue(ED: tTntEdit;UD: tUpDown;var CardValue: real);
var
rVal : real;
begin
if MainForm.CheckRealStr(ED.Text,rVal,'.') or
MainForm.CheckRealStr(ED.Text,rVal,',') then
begin
if rVal <= (UD.Min/10) then rVal := (UD.Min/10);
if rVal >= (UD.Max/10) then rVal := (UD.Max/10);
CardValue := rVal;
UD.Position := Round(CardValue*10);
ED.Text := FormatFloat('0.0', UD.Position/10 );
end
else
ED.Text := FormatFloat('0.0', UD.Position/10 );
end;
procedure TForm.updownClick(Sender: TObject;
Button: TUDBtnType);
begin
edit.Text := FormatFloat('0.0', updown.Position/10 );
end;
As you can see, UpDown might have position between 300 and 900, thats mean that edit.Text is from '30.0' to '90,0'. If Text is set to 89.8 and we use up arrow of updown to increase it's position, then text in edit will change as follows: '89.9'->'90.0'->'900' and stopes. When edit.text is changing from '90.0' to '900', updownClick event is not even called!
So here is my questions:
Upvotes: 0
Views: 8485
Reputation: 16045
Remove
updown.Assosiate := edit;
Either it is UpDown control changing the value, or you do by your custom code.
There is nothing good in having two contradicting masters for same issue. if you custom-tailored SetValue
then don't let the UpDown
's built-in functions step in the way.
And better use some ready spin-buttoned edits with native support for float numbers.
PS. You may wish to setup Edit.OnExit
so that it would parse user-typed text and adjust UpDown.Value
accordingly
Upvotes: 1