Einzelnen Beitrag anzeigen

michaelg

Registriert seit: 20. Apr 2008
87 Beiträge
 
#17

AW: Modaler Doppelklick gibt Event an Ursprungsfenster weiter

  Alt 12. Sep 2018, 10:19
Erstmal vielen Dank an alle, die sich meinen Kopf zerbrochen haben. Ich bin begeistert über so viel Mithilfe.

Die Lösung von Schokohase funktioniert super.

Delphi-Quellcode:
unit Forms.SomeDialogForm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.StdCtrls, Vcl.ExtCtrls,
  Vcl.AppEvnts;

type
  TSomeDialogForm = class( TForm )
    ApplicationEvents1: TApplicationEvents;
    procedure ApplicationEvents1Idle(
      Sender: TObject;
      var Done: Boolean );
    procedure FormDblClick( Sender: TObject );
  private
    FModalResult: TModalResult;
    procedure SetModalResult( const Value: TModalResult );
  public
  end;

var
  SomeDialogForm: TSomeDialogForm;

implementation

{$R *.dfm}

procedure TSomeDialogForm.ApplicationEvents1Idle(
  Sender: TObject;
  var Done: Boolean );
begin
  if ( FModalResult <> 0 ) and ( GetAsyncKeyState( VK_LBUTTON ) = 0 )
  then
    begin
      // Wir setzen den ModalResult erst dann, wenn der linke Maus-Button nicht gedrückt ist
      ModalResult := FModalResult;
    end;
end;

procedure TSomeDialogForm.FormDblClick( Sender: TObject );
begin
  SetModalResult( mrOK );
end;

procedure TSomeDialogForm.SetModalResult( const Value: TModalResult );
begin
  if ( Value <> Self.ModalResult ) or ( Value <> FModalResult )
  then
    begin
      FModalResult := Value;
    end;
end;

end.
Ich weiss nur nicht, ob es Auswirkungen hat, dass ich im Mainform des Programms bereits ein tApplicationEvents habe. Arbeitet das dann auch noch, wenn mein modaler Dialog gerade angezeit wird?
  Mit Zitat antworten Zitat