180 lines
4.6 KiB
ObjectPascal
180 lines
4.6 KiB
ObjectPascal
|
|
unit uDialogUtils;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Controls, SysUtils;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TDlgButton = (TDlgButton_SI, TDlgButton_NO, TDlgButton_CANCELAR,
|
|||
|
|
TDlgButton_ACEPTAR, TDlgButton_OK, TDlgButton_CERRAR);
|
|||
|
|
TDlgButtonSet = set of TDlgButton;
|
|||
|
|
|
|||
|
|
procedure ShowInfoMessage(const AMessage : String);
|
|||
|
|
procedure ShowWarningMessage(const AMessage : String);
|
|||
|
|
procedure ShowErrorMessage(const AHeader : String; const AMessage : String); overload;
|
|||
|
|
procedure ShowErrorMessage(const AHeader : String; const AMessage : String; AException: Exception); overload;
|
|||
|
|
|
|||
|
|
function ShowConfirmMessage(const AHeader : String;
|
|||
|
|
const AMessage : String) : TModalResult; overload;
|
|||
|
|
|
|||
|
|
function ShowConfirmMessage(const ATitle : String;
|
|||
|
|
const AHeader : String;
|
|||
|
|
const AMessage : String;
|
|||
|
|
const AButtonSet: TDlgButtonSet) : TModalResult; overload;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Forms,
|
|||
|
|
JSDialog,
|
|||
|
|
JSDialogs,
|
|||
|
|
Classes;
|
|||
|
|
|
|||
|
|
const
|
|||
|
|
sBtnSi = '&Si';
|
|||
|
|
sBtnNo = '&No';
|
|||
|
|
sBtnCancelar = '&Cancelar';
|
|||
|
|
sBtnAceptar = '&Aceptar';
|
|||
|
|
sBtnOK = '&OK';
|
|||
|
|
sBtnCerrar = '&Cerrar';
|
|||
|
|
|
|||
|
|
function CreateTaskDialog(const ATitle: String;
|
|||
|
|
const AInstruction: String;
|
|||
|
|
const AMessage: String;
|
|||
|
|
const AIcon: TTaskDialogIcon): TJSDialog;
|
|||
|
|
var
|
|||
|
|
ADialog : TJSDialog;
|
|||
|
|
begin
|
|||
|
|
ADialog := TJSDialog.Create(NIL);
|
|||
|
|
with ADialog do
|
|||
|
|
begin
|
|||
|
|
Position := dpScreenCenter;
|
|||
|
|
ButtonBar.Buttons := [];
|
|||
|
|
DialogOptions := [doModal];
|
|||
|
|
|
|||
|
|
Title := ATitle;
|
|||
|
|
Instruction.Text := AInstruction;
|
|||
|
|
Content.Text := AMessage;
|
|||
|
|
MainIcon := AIcon;
|
|||
|
|
end;
|
|||
|
|
Result := ADialog;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure CreateCustomButtons(const AButtonSet: TDlgButtonSet;
|
|||
|
|
ACustomButtons : TJSCustomButtons);
|
|||
|
|
|
|||
|
|
function CreateButton(const ACaption: String; const AModalResult: TModalResult): TJSCustomButtonItem;
|
|||
|
|
begin
|
|||
|
|
Result := ACustomButtons.Add;
|
|||
|
|
Result.Caption := ACaption;
|
|||
|
|
Result.ModalResult := AModalResult;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
with ACustomButtons do
|
|||
|
|
begin
|
|||
|
|
Clear;
|
|||
|
|
|
|||
|
|
if TDlgButton_SI in AButtonSet then
|
|||
|
|
CreateButton(sBtnSi, mrYes);
|
|||
|
|
|
|||
|
|
if TDlgButton_NO in AButtonSet then
|
|||
|
|
CreateButton(sBtnNo, mrNo);
|
|||
|
|
|
|||
|
|
if TDlgButton_CANCELAR in AButtonSet then
|
|||
|
|
CreateButton(sBtnCancelar, mrCancel);
|
|||
|
|
|
|||
|
|
if TDlgButton_ACEPTAR in AButtonSet then
|
|||
|
|
CreateButton(sBtnAceptar, mrOk);
|
|||
|
|
|
|||
|
|
if TDlgButton_OK in AButtonSet then
|
|||
|
|
CreateButton(sBtnOK, mrOk);
|
|||
|
|
|
|||
|
|
if TDlgButton_CERRAR in AButtonSet then
|
|||
|
|
CreateButton(sBtnCerrar, mrNone);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure ShowInfoMessage(const AMessage : String);
|
|||
|
|
var
|
|||
|
|
ADialog : TJSDialog;
|
|||
|
|
begin
|
|||
|
|
ADialog := CreateTaskDialog('Informaci<63>n', '', AMessage, tdiWarning);
|
|||
|
|
try
|
|||
|
|
CreateCustomButtons([TDlgButton_CERRAR], ADialog.CustomButtons);
|
|||
|
|
ADialog.Execute;
|
|||
|
|
finally
|
|||
|
|
FreeAndNIL(ADialog);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure ShowWarningMessage(const AMessage : String);
|
|||
|
|
var
|
|||
|
|
ADialog : TJSDialog;
|
|||
|
|
begin
|
|||
|
|
ADialog := CreateTaskDialog('<27>Atenci<63>n!', '', AMessage, tdiWarning);
|
|||
|
|
try
|
|||
|
|
CreateCustomButtons([TDlgButton_CERRAR], ADialog.CustomButtons);
|
|||
|
|
ADialog.Execute;
|
|||
|
|
finally
|
|||
|
|
FreeAndNIL(ADialog);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure ShowErrorMessage(const AHeader : String; const AMessage : String);
|
|||
|
|
var
|
|||
|
|
ADialog : TJSDialog;
|
|||
|
|
begin
|
|||
|
|
ADialog := CreateTaskDialog(Application.Title, AHeader, AMessage, tdiError);
|
|||
|
|
try
|
|||
|
|
CreateCustomButtons([TDlgButton_CERRAR], ADialog.CustomButtons);
|
|||
|
|
ADialog.Execute;
|
|||
|
|
finally
|
|||
|
|
FreeAndNIL(ADialog);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure ShowErrorMessage(const AHeader : String; const AMessage : String; AException: Exception);
|
|||
|
|
var
|
|||
|
|
ADialog : TJSDialog;
|
|||
|
|
begin
|
|||
|
|
ADialog := CreateTaskDialog(Application.Title, AHeader, AMessage, tdiError);
|
|||
|
|
try
|
|||
|
|
CreateCustomButtons([TDlgButton_CERRAR], ADialog.CustomButtons);
|
|||
|
|
ADialog.Expando.Lines.Text := AException.Message;
|
|||
|
|
ADialog.Expando.ShowText := 'Mostrar informaci<63>n sobre el error';
|
|||
|
|
ADialog.Expando.HideText := 'No mostrar informaci<63>n sobre el error';
|
|||
|
|
ADialog.Expando.Visible := True;
|
|||
|
|
ADialog.Execute;
|
|||
|
|
finally
|
|||
|
|
FreeAndNIL(ADialog);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function ShowConfirmMessage(const AHeader : String;
|
|||
|
|
const AMessage : String) : TModalResult;
|
|||
|
|
begin
|
|||
|
|
Result := ShowConfirmMessage(Application.Title, AHeader,
|
|||
|
|
AMessage, [TDlgButton_SI, TDlgButton_NO]);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function ShowConfirmMessage(const ATitle : String;
|
|||
|
|
const AHeader : String;
|
|||
|
|
const AMessage : String;
|
|||
|
|
const AButtonSet: TDlgButtonSet) : TModalResult;
|
|||
|
|
var
|
|||
|
|
ADialog : TJSDialog;
|
|||
|
|
begin
|
|||
|
|
ADialog := CreateTaskDialog(Application.Title, AHeader, AMessage, tdiConfirmation);
|
|||
|
|
try
|
|||
|
|
CreateCustomButtons(AButtonSet, ADialog.CustomButtons);
|
|||
|
|
Result := ADialog.Execute;
|
|||
|
|
finally
|
|||
|
|
FreeAndNIL(ADialog);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|
|||
|
|
|