Skip to content

Instantly share code, notes, and snippets.

@jpluimers
Forked from edwinyzh/NonBlockingDlgHelperU.pas
Created November 14, 2017 08:04
Show Gist options
  • Save jpluimers/66d5c59d755fce0d714032735b69d647 to your computer and use it in GitHub Desktop.
Save jpluimers/66d5c59d755fce0d714032735b69d647 to your computer and use it in GitHub Desktop.
Idea for aIdea for a Non-blocking dialoguing mechanism (https://plus.google.com/u/0/115543678481226143222/posts/46dTfcuVVLP?cfem=1)
unit NonBlockingDlgHelperU;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
const
WM_ShowDlgA = WM_APP + 1;
WM_ShowDlgB = WM_APP + 2;
type
(*
Idea for a Non-blocking dialoguing mechanism.
In other parts of your software you cal it like this:
PostMessage(NonBlockingDlgHelper.Handle, WM_ShowDlgA, PChar(aString), CastAnnoMethodToLParam(SomeFunc));
*)
TNonBlockingDlgHelper = class(TForm)
private
public
procedure WMShowDlgA(var Message: TMessage); message WM_SHOWDLGA;
procedure WMShowDlgB(var Message: TMessage); message WM_SHOWDLGB;
end;
var
NonBlockingDlgHelper: TNonBlockingDlgHelper;
implementation
{$R *.dfm}
procedure TNonBlockingDlgHelper.WMShowDlgA(var Message: TMessage);
begin
inherited;
if Application.MessageBox(PChar(Message.WParam), '', MB_OKCANCEL) = IDCANCEL then
PostMessage(Self.Handle, WM_ShowDlgB, 0, 0);
// note: Also consider to use TMessage.LParam to pass in a 'OnClose' Anno. method object.
end;
procedure TNonBlockingDlgHelper.WMShowDlgB(var Message: TMessage);
begin
inherited;
Application.MessageBox('So you have cancelled', '', MB_OKCANCEL);
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment