Recent

Author Topic: [SOLVED] Strange behavior with double click in BitBtn  (Read 5895 times)

clauslack

  • Sr. Member
  • ****
  • Posts: 275
[SOLVED] Strange behavior with double click in BitBtn
« on: March 01, 2010, 08:10:39 pm »
Strange behavior with double click in BitBtn.

I have a program for insert data with this cycle
Click a BitBtn->DoubleClick Dbgrid->Click a BitBtn->DoubleClick Dbgrid, etc, etc

But, some Newbie users, does a DoubleClick in BitBtn, and the BitBtn1Click procedure run twice
and show an Access Violation. For avoid that I do it that.

Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
begin
   BitBtn1.caption:='1';
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var nro:integer;
begin
   BitBtn1.Enabled:=False;
   nro:=StrToInt(BitBtn1.caption);
   sleep(1000);
   inc(nro);
   BitBtn1.caption:=IntToStr(nro);
   BitBtn1.Enabled:=True;
end;


But with double click in BitBtn the procedure still does run twice.(nro=2)

How can I run the BitBtn1Click only one time, even when the user does a doble click in BitBtn?

Tested with Lazarus 0.9.29 svn 23817 fpc 2.5.1
Delphi 5 show the same behavior.

Any Idea?
Thanks
« Last Edit: March 12, 2010, 12:40:26 pm by clauslack »

clauslack

  • Sr. Member
  • ****
  • Posts: 275
Re: [SOLVED] Strange behavior with double click in BitBtn
« Reply #1 on: March 12, 2010, 12:45:09 pm »
I used a simple flag for run once the code (work fine for the example above), but in the main programa still  show A.V.
But I found the problem.
QueueAsyncCall
http://wiki.lazarus.freepascal.org/Asynchronous_Calls

Async call is only executed after the Button Click event has finished.

So now works fine.


 

TinyPortal © 2005-2018