Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
Ad Blocking Detected
Please consider disabling your ad blocker for our website.
We rely on these ads to be able to run our website.
You can of course support us in other ways (see Support Us).
Some (sloppy) code I threw together when I was playing with "CocoaPromptUser" which shows a macOS correct modal dialog. The idea was to make an overload for MessageDlg (the last parameter, the form, would be the difference). (I've also posted my code also in the official Lazarus forum)
unit Unit1;
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls
, CocoaInt, CocoaAll;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
function MessageDlg( aCaption, aMsg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn; const Sender:TForm): TModalResult;
var
ButtonArrayPtr : PLongint; // Pointer to the button array
ButtonCount : Integer; // Number of buttons
Counter : integer;
NSParentWindow : NSWindow; // Parent Form that the sheet is attached to
DlgTypeID : longint; // DialogType for conversion from TMsgDlgType
ButtonIDs : array of Longint; // ButtonTypes for conversion from TMsgDlgBtn array
ButtonPressed : longint; // ModalResult which gets converted to TModalResult
aButton : TMsgDlgBtn;
DefaultButtonIndex : integer;
ReversedButtons : TMsgDlgButtons;
begin
// Show regular message dialog if no form assigned or form not showing
if (not Assigned(Sender)) or (not Sender.Visible) then
begin
Result := MessageDlg(aCaption, aMsg, DlgType, Buttons, HelpCtx, DefaultButton, Sender);
exit;
end;
{ Convert array of TMsgDlgBtn to idButtonXYZ (See LCLType) and convert default button (TMsgDlgBtn) to index }
ButtonCount := 0;
DefaultButtonIndex := -1;
ReversedButtons := [];
Result := mrNone;
if Buttons<>[] then
begin
for aButton in Buttons do
ReversedButtons := [aButton] + ReversedButtons;
for aButton in ReversedButtons do
begin
SetLength(ButtonIDs,ButtonCount+1);
case aButton of
mbYes : ButtonIDs[ButtonCount]:= 4;
mbNo : ButtonIDs[ButtonCount]:= 5;
mbOK : ButtonIDs[ButtonCount]:= 1;
mbCancel : ButtonIDs[ButtonCount]:= 2;
mbAbort : ButtonIDs[ButtonCount]:= 7;
mbRetry : ButtonIDs[ButtonCount]:= 8;
mbIgnore : ButtonIDs[ButtonCount]:= 9;
mbAll : ButtonIDs[ButtonCount]:= 10;
mbNoToAll : ButtonIDs[ButtonCount]:= 12;
mbYesToAll : ButtonIDs[ButtonCount]:= 11;
mbHelp : ButtonIDs[ButtonCount]:= 3;
else ButtonIDs[ButtonCount]:= 6; // mbClose
end;
if (aButton=DefaultButton) then
DefaultButtonIndex := ButtonCount;
inc(ButtonCount);
end;
end;
if (ButtonCount>0) then
ButtonArrayPtr:=@{%H-}ButtonIDs[0]{%H+}
else
ButtonArrayPtr:=nil;
{ Convert TMsgDlgType to idDialogXYZ (See LCLType) }
case DlgType of
mtWarning : DlgTypeID := $FF +1;
mtError : DlgTypeID := $FF +2;
mtInformation : DlgTypeID := $FF +3;
mtConfirmation : DlgTypeID := $FF +4;
else DlgTypeID := $FF +5; //mtCustom:
end;
NSParentWindow := nil;
if Assigned(Sender) then
begin
if not Sender.HandleAllocated then Exit;
NSParentWindow := NSView(Sender.Handle).window;
end
else
NSParentWindow := NSApplication.sharedApplication.keyWindow;
if Assigned(NSParentWindow) then
begin
ButtonPressed := CocoaPromptUser(aCaption, aMsg ,DlgTypeID, ButtonArrayPtr, ButtonCount, DefaultButtonIndex, 0, NSParentWindow, true);
case ButtonPressed of
1 : Result := mrOK;
2 : Result := mrCancel;
//3: Result := mrHelp // Help does not return from modal;
4 : Result := mrYes;
5 : Result := mrNo;
6 : Result := mrClose;
7 : Result := mrAbort;
8 : Result := mrRetry;
9 : Result := mrIgnore;
10 : Result := mrAll;
11 : Result := mrYesToAll;
12 : Result := mrNoToAll
else Result := mrNone;
end;
end
else
Result := mrNone;
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
MessageDlg('Caption','',mtInformation,[mbYes,mbNo,mbIgnore],0,mbYes,self);
end;
end.
Please consider disabling your ad blocker for our website.
We rely on these ads to be able to run our website.
You can of course support us in other ways (see Support Us).
Osceola, WI My other home-town ... love living there! Osceola rocks!
Lazarus / FPC Lazarus / Free Pascal Compiler - A cross platform software development environment that show similarities with the good old Delphi.
RegExr Awesome website to play and experiment with regular expression!
Robots.txt Analyzer Very simple and effective tool for online checking of your robots.txt file without having to use Google Webmaster Tools.
HandBrake Great tool for ripping DVD's and converting video.
VLC - VideoLAN Media Player One of the most flexible media players around and available on multiple computer platforms. Handles pretty much any audio and video type available and plays DVD as well.
Links Page These and more of our favorite links can be found on the Links Page.
New Downloads
ConnectMeNow4-v4.0.11-macOS-x86-64.dmgDate: 2023-10-21 - Size: 3.5 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Intel version which works on Intel and Apple Silicon Macs.
ConnectMeNow4-v4.0.11-macOS-arm64.dmgDate: 2023-10-21 - Size: 3 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Apple Silicon version (not suitable for Intel).
MiniWOL2 MacOS (64 bits Apple Silicon)Date: 2023-08-01 - Size: 1.2 MBminiWol is a simple, but effective application to send Wake On LAN to network devices. This is the signed 64 bit MacOS ARM (Apple Silicon) version.
MovieScanner2-2.2.3-Windows-32bit-setup.exeDate: 2023-04-12 - Size: 18.6 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 32 bit Windows version.
MovieScanner2-2.2.2-Linux-GTK-64bits.tar.gzDate: 2023-04-11 - Size: 29.2 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for GTK.
MovieScanner2-2.2.2-Linux-QT5-64bits.tar.gzDate: 2023-04-11 - Size: 29.1 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for QT5.
Downloads Page Find these and more Downloads on the Downloads Page, where you will also find articles references, operating system requirements and categories.
Amazon Ads
Support us by doing your shopping at Amazon.com, either click the link, or click one of the links below …
You can also sponsor us through these Amazon offerings:
Please consider disabling your ad blocker for our website.We rely on these ads to be able to run our website.You can of course support us in other ways (see Support Us on the left).