Re: [Lazarus] Proposal for CreateMessageDialog() function

2008-11-04 Thread Reenen Laurie
I would love to have the function... I didn't have time to test or try your
code though.

Also creating stuff that make Laz more compatible with Delphi is part of the
aim of Lazarus (even though it's improving in other areas beyond!).

On Mon, Nov 3, 2008 at 10:28 PM, Bart [EMAIL PROTECTED] wrote:

 Hi,

 Currently Lazarus has no CreateMessagedialog function, whereas Delphi has.

 function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
 Buttons: TMsgDlgButtons): TForm;

 This function returns the actual form of the messagedialog, and so
 gives the programmer access to all the controls on this dialog form.
 In Delphi 3 I used this to access the captions of the buttons and do
 an on the fly translation.
 Given that we Lazarus can use .po files to translae the
 resourcestrings for the captions, this is not necessary anymore.

 However, another use of this function is to add controls to the dialog
 form, thus creating customized message dialog variants.
 One example of this is adding a checkbox with a caption like Don't
 show this dialog again, which is quit useful.
 (See
 http://i25.photobucket.com/albums/c74/Talent111/devel/messagedlg_with_checkbox.png
 for an example of this)

 A long time ago I posted bugreport #0008186 on Mantis (Feature
 request: make it possible to add controls to MessageDlg()).
 At that time I was new to Lazarus, and saw no opportunity to
 accomplish the task myself.

 Lately however, browsing dialogs.pp (more specifically
 promptdialog.inc), I noticed that most of the work was already done.

 So my proposal is like this:

 Declare CreateMessageDialog in the interface of  dialogs.pp.
 Adjust promptdialog.inc more or less like this:

 function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
 Buttons: TMsgDlgButtons): TForm;
 var PDlg: TPromptDialog;
aCaption: String;
Btns: PLongInt;
CancelValue, DefaultIndex, ButtonCount: Longint;
UseDefButton: Boolean; DefButton: TMsgDlgBtn;
 begin
  if DlgType  mtCustom then
aCaption := MsgDlgCaptions[DlgType]
  else
aCaption := Application.Title;
  UseDefButton := False;
  Btns := GetPromptUserButtons(Buttons, CancelValue, DefaultIndex,
 ButtonCount,
   UseDefButton, DefButton);
  DebugLn('CancelValue = ',ModalResToStr(CancelValue));
  PDlg := TPromptDialog.CreateMessageDialog(aCaption, Msg,
 DialogIds[DlgType], Btns, ButtonCount, DefaultIndex);
  Result := TForm(PDlg);

  //??? Is this save to do
  ReallocMem(Btns, 0);
 end;

 A tipical use of this function would the be like:

 procedure TForm1.ShowBtnClick(Sender: TObject);
 var Dlg: TForm;
Res: TModalResult;
DT: TMsgDlgType;
Title,Msg: String;
Btns: TMsgDlgButtons;
i: Integer;
 begin
  Title := TitleEdit.Text;
  Msg := MsgMemo.Text;
  case DTGroup.ItemIndex of
0: DT := mtCustom;
1: DT := mtError;
2: DT := mtWarning;
3: DT := mtInformation;
4: DT := mtConfirmation;
  end;
  Btns := [mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,
   mbAll, mbNoToAll, mbYesToAll, mbHelp, mbClose];
  Dlg := CreateMessageDialog(Msg,DT, Btns);

  ...
  DoSomethingWithTheDialogForm; //Add a checkbox for example
  ...

  try
Res := Dlg.ShowModal;
  Finally
Dlg.Free;
  end;
 end;

 Users should be aware that a Modalresult of -1 means that the Escape
 key was pressed.


 I'd really appreciate your suggestions and ideas on this one,
 especially on the Is this safe to do remark in my code.

 Bart
 ___
 Lazarus mailing list
 Lazarus@lazarus.freepascal.org
 http://www.lazarus.freepascal.org/mailman/listinfo/lazarus




-- 
o__
,_./ _
(_)_\(_)___
...speed is good
___
I believe five out of four people have a problem with fractions.
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Proposal for CreateMessageDialog() function

2008-11-03 Thread Bart
Hi,

Currently Lazarus has no CreateMessagedialog function, whereas Delphi has.

function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons): TForm;

This function returns the actual form of the messagedialog, and so
gives the programmer access to all the controls on this dialog form.
In Delphi 3 I used this to access the captions of the buttons and do
an on the fly translation.
Given that we Lazarus can use .po files to translae the
resourcestrings for the captions, this is not necessary anymore.

However, another use of this function is to add controls to the dialog
form, thus creating customized message dialog variants.
One example of this is adding a checkbox with a caption like Don't
show this dialog again, which is quit useful.
(See 
http://i25.photobucket.com/albums/c74/Talent111/devel/messagedlg_with_checkbox.png
for an example of this)

A long time ago I posted bugreport #0008186 on Mantis (Feature
request: make it possible to add controls to MessageDlg()).
At that time I was new to Lazarus, and saw no opportunity to
accomplish the task myself.

Lately however, browsing dialogs.pp (more specifically
promptdialog.inc), I noticed that most of the work was already done.

So my proposal is like this:

Declare CreateMessageDialog in the interface of  dialogs.pp.
Adjust promptdialog.inc more or less like this:

function CreateMessageDialog(const Msg: string; DlgType: TMsgDlgType;
 Buttons: TMsgDlgButtons): TForm;
var PDlg: TPromptDialog;
aCaption: String;
Btns: PLongInt;
CancelValue, DefaultIndex, ButtonCount: Longint;
UseDefButton: Boolean; DefButton: TMsgDlgBtn;
begin
  if DlgType  mtCustom then
aCaption := MsgDlgCaptions[DlgType]
  else
aCaption := Application.Title;
  UseDefButton := False;
  Btns := GetPromptUserButtons(Buttons, CancelValue, DefaultIndex, ButtonCount,
   UseDefButton, DefButton);
  DebugLn('CancelValue = ',ModalResToStr(CancelValue));
  PDlg := TPromptDialog.CreateMessageDialog(aCaption, Msg,
DialogIds[DlgType], Btns, ButtonCount, DefaultIndex);
  Result := TForm(PDlg);

  //??? Is this save to do
  ReallocMem(Btns, 0);
end;

A tipical use of this function would the be like:

procedure TForm1.ShowBtnClick(Sender: TObject);
var Dlg: TForm;
Res: TModalResult;
DT: TMsgDlgType;
Title,Msg: String;
Btns: TMsgDlgButtons;
i: Integer;
begin
  Title := TitleEdit.Text;
  Msg := MsgMemo.Text;
  case DTGroup.ItemIndex of
0: DT := mtCustom;
1: DT := mtError;
2: DT := mtWarning;
3: DT := mtInformation;
4: DT := mtConfirmation;
  end;
  Btns := [mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,
   mbAll, mbNoToAll, mbYesToAll, mbHelp, mbClose];
  Dlg := CreateMessageDialog(Msg,DT, Btns);

  ...
  DoSomethingWithTheDialogForm; //Add a checkbox for example
  ...

  try
Res := Dlg.ShowModal;
  Finally
Dlg.Free;
  end;
end;

Users should be aware that a Modalresult of -1 means that the Escape
key was pressed.


I'd really appreciate your suggestions and ideas on this one,
especially on the Is this safe to do remark in my code.

Bart
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus