I'm following this example: http://lawrencebarsanti.wordpress.com/2009/12/16/display-error-messages-with-tballoonhint/
I'm trying to only show a balloon hint when the current value in the edit box is not acceptable. The check is triggered when OnExit
. The balloon should still be allowed to display until the value is determined to be OK. I'm also trying to programmatically show the balloon as soon as the user leaves the edit to show the initial error.
The code works, but not the first time. I have to leave once with an invalid value, change to an acceptable one, then come back and use an invalid one again. I think this is because I can't enable or disable the ShowHint property right before I try to show the balloon.
Here is my code:
procedure TForm1.Edit1Exit(Sender: TObject);
var
R: TRect;
Bad : Boolean;
begin
//Check if edit has only numbers
if StrIsReal(Edit1.Text) then
begin
if(StrToFloat(Edit1.Text) >= 0.5) then
begin
//Value is ok
SpeedButton1.Visible := false;
Edit1.ShowHint := false;
BalloonHint1.HideHint;
Edit1.Text := FloatToStrF(StrToFloat(Edit1.Text), ffFixed, 8, 2);
end
else
begin
//Is decimal, but not at least 0.5
Bad := true;
end;
end
else
begin
Bad := true;
end;
if Bad then
begin
//Invalid number
Edit1.ShowHint := true;
Edit1.Text := '0.00';
SpeedButton1.Visible := true;
R := Edit1.BoundsRect;
R.TopLeft := ClientToScreen(R.TopLeft);
R.BottomRight := ClientToScreen(R.BottomRight);
BalloonHint1.ShowHint(R); //!!! Issue: No hint the first time around
end;
end;
How can I show the balloon conditionally right when I check for a valid value (leaving the edit)?