Jump to content
alank2

TSpeedButton IsPressed issue

Recommended Posts

I created a TSpeedButton and set the StaysPressed property to true.

 

I then was using IsPressed to see if it is pressed or not in the OnClick event.

 

If I click it slowly it works, but if I click it quickly, the 2nd time the event is fired (and it does fire), the IsPressed property is not changed, but is the previous state.

 

 

void __fastcall TTest::UpdateSearch()
{

//debug does it fire when clicked fast
static int i1;
i1++;
Label1->Text=i1;

  if (Search[0]==0)
    {
      if (SBSpecialOnly->IsPressed)
        LSearch->Text="Type to search special";
      else LSearch->Text="Type to search";
      LSearch->FontColor=claDarkgray;
    }
  else
    {
      LSearch->FontColor=claBlack;
      LSearch->Text=Search;
    }
}

 

Edited by alank2

Share this post


Link to post

Hello,

 

you are right, I can reproduce the issue. I used a listbox to record the IsPressed status in three events. If you click quickly, you can see that the status in OnClick has not changed yet. You can use the OnMouseUp event instead.


 

procedure TForm4.btnSpecialOnlyMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  if btnSpecialOnly.IsPressed then begin
    LB.Items.Add('MouseDown TRUE');
  end else begin
    LB.Items.Add('MouseDown FALSE');
  end;
end;

procedure TForm4.btnSpecialOnlyClick(Sender: TObject);
begin
  Label1.Text:=FCount.ToString;
  Inc(FCount);
  if btnSpecialOnly.IsPressed then begin
    LB.Items.Add('Click TRUE');
  end else begin
    LB.Items.Add('Click FALSE');
  end;
end;

procedure TForm4.btnSpecialOnlyMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
begin
  if btnSpecialOnly.IsPressed then begin
    LB.Items.Add('MouseUp TRUE');
  end else begin
    LB.Items.Add('MouseUp FALSE');
  end;
end;

 

Share this post


Link to post

It seems to be an immediate type thing.  If I have code that looks at IsPressed later on, it seems to be correct, but not always in the OnClick that is changing it.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×