Autor Beitrag
user32
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 55
Erhaltene Danke: 5



BeitragVerfasst: Di 12.12.17 16:34 
Ich führe eine lange Berechnung durch, und will verhindern, dass man versehentlich zwei- oder mehrmals auf den Button klickt.

Selbst mit diesem Code klappt es erstaunlicherweise NICHT:


Bei Button Onclick am Anfang der Berechnung:

ausblenden Delphi-Quelltext
1:
2:
3:
  button1.Enabled := false;
 if inprogress then exit;
  inprogress := true;

Am Ende:
ausblenden Delphi-Quelltext
1:
2:
  inprogress := false;
  button1.Enabled := true;


Wenn ich ganz schnell doppel-klicke, wird die Prozedur mehrmals hintereinander ausgeführt.
Ich vermute es liegt an den Windows Messages, muss ich da eingreifen?


Moderiert von user profile iconNarses: Topic aus Windows API verschoben am Di 12.12.2017 um 19:50
Symbroson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 382
Erhaltene Danke: 67

Raspbian, Ubuntu, Win10
C, C++, Python, JavaScript, Lazarus, Delphi7, Casio Basic
BeitragVerfasst: Di 12.12.17 16:38 
versuchs mal mit application.processmessages nach dem enabled := false

_________________
most good programmers do programming not because they expect to get paid or get adulation by the public, but because it's fun to program. (Linus Torvalds)
user32 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 55
Erhaltene Danke: 5



BeitragVerfasst: Di 12.12.17 18:17 
Damit ist es wohl etwas besser, aber oft läuft es immer noch 2x.
Symbroson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 382
Erhaltene Danke: 67

Raspbian, Ubuntu, Win10
C, C++, Python, JavaScript, Lazarus, Delphi7, Casio Basic
BeitragVerfasst: Di 12.12.17 18:25 
ich verstehe was du meinst - ich probier mal bissl rum ^^

_________________
most good programmers do programming not because they expect to get paid or get adulation by the public, but because it's fun to program. (Linus Torvalds)
Symbroson
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 382
Erhaltene Danke: 67

Raspbian, Ubuntu, Win10
C, C++, Python, JavaScript, Lazarus, Delphi7, Casio Basic
BeitragVerfasst: Di 12.12.17 18:33 
es funktioniert, wenn du Application.ProcessMessages; aufrufst bevor du den Button wieder aktivierst.
Sonst werden die User-Inputs erst wieder abgefragt, nachdem die Prozedur / Funktion verlassen wird, weil der Main-Thread während der Ausführung einer Prozedur diesen blockiert.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  if not inprogress then begin
    Button1.Enabled := false;
    inprogress := true;

    Memo1.Lines.Add('hello');
    sleep(1000);

    inprogress := false;
    Application.ProcessMessages;
    button1.Enabled := true;
  end;

_________________
most good programmers do programming not because they expect to get paid or get adulation by the public, but because it's fun to program. (Linus Torvalds)
user32 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 55
Erhaltene Danke: 5



BeitragVerfasst: Mi 13.12.17 08:08 
So geht es. Stimmt, danke !