Frage

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:

  1. why value '900' appears;
  2. why updownClick event is not called;
War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top