Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > SpeedButton и RadioButton глюк на OnMouseDown


Автор: Litta 17.5.2011, 16:08
Приветствую!
Столкнулся с такой проблемой и не могу понять в чём фишка.
В проекте нужен контроль за нажатием на RadioButton-ы, контроль сделан через событие OnMouseDown. Все работает, по крайней мере так было, пока не обнаружил, совершенно случайно слудующую фишку:
нажимая на RadioButton2 видим, что выбрать его нельзя по каким-то причинам, соответственно отлавливаем какой RadioButton был нажат до того и присваеваем Checked ему, но если после этого нажать на SpeedButton (именно SpeedButton,а не просто Button - в этом вся соль), в коде которого стоит любой ShowMessage - точка выбора RadioButton перепрыгивает на ту RadioButton, на который пытались нажать.
На всякий случай сделал простой проект с RadioButton-ами, кнопкой "с сообщением" и кнопкой имитирующей условие блокировки нажатия, вот код проекта:
Код

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    Label1: TLabel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    Label2: TLabel;
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure RadioButton1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure RadioButton2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure RadioButton3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Math;

{$R *.dfm}

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
if Label2.Caption='1' then
 Label2.Caption:='0'
else
 Label2.Caption:='1'; 
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
ShowMessage('dddd');
end;

procedure TForm1.RadioButton1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i:integer;
begin
if RadioButton2.Checked then
 i:=2
else
 i:=3;
if Label2.Caption='1' then
 begin
  ShowMessage('fuck');
  if i=2 then
   RadioButton2.Checked:=True
  else
   RadioButton3.Checked:=True;
 end
else
 begin
  label1.Caption:=RadioButton1.Name;
 end;
end;

procedure TForm1.RadioButton2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i:integer;
begin
if RadioButton3.Checked then
 i:=2
else
 i:=3;
if Label2.Caption='1' then
 begin
  ShowMessage('fuck');
  if i=2 then
   RadioButton3.Checked:=True
  else
   RadioButton1.Checked:=True;
 end
else
 begin
  label1.Caption:=RadioButton2.Name;
 end;
end;

procedure TForm1.RadioButton3MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
i:integer;
begin
if RadioButton2.Checked then
 i:=2
else
 i:=3;
if Label2.Caption='1' then
 begin
  ShowMessage('fuck');
  if i=2 then
   RadioButton2.Checked:=True
  else
   RadioButton1.Checked:=True;
 end
else
 begin
  label1.Caption:=RadioButton3.Name;
 end;
end;

end.


Т.е. если нажать SpeedButton2 и симитируем условие блокировки, то нажатие на любой "пустой" RadioButton не приведёт к его Checked, но если сразу нажать на SpeedButton1 - появится сообщение, а после этого сразу Check-ается тот RadioButton на который нажимали до этого.
Если заменить SpeedButton на Button, то все ок, но со SpeedButton-ом происходит ерунда!
Кто-нибудь сталкивался с такой проблемой?

PS: Delphi 7

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)