Demo学习: Dialogs Anonymous Callback
Dialogs\Dialogs Anonymous Callback
窗体回调函数使用.
1. 标准回调函数
ShowMessage(const Msg: string; CallBack: TUniDialogCallBackProc = nil)
procedure TMainForm.UniButton2Click(Sender: TObject); begin ShowMessage('Message-2', CallBack1); end;
//定义回调函数 procedure TMainForm.CallBack1(Res: Integer); begin //OK返回1, 取消返回2; UniMemo1.Lines.Add('Result-1: '+IntToStr(Res)); end;
2. MessageDlg(const Msg:string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; CallBack:TUniDialogCallBackProc)
procedure TMainForm.UniButton7Click(Sender: TObject); begin MessageDlg('mbYesNo', mtConfirmation, mbYesNo, DCallBack4); end; procedure TMainForm.DCallBack4(Res: Integer); begin case Res of mrYes : UniMemo1.Lines.Add('DResult: YES'); mrNo : UniMemo1.Lines.Add('DResult: NO'); mrOK : UniMemo1.Lines.Add('DResult: OK'); mrCancel : UniMemo1.Lines.Add('DResult: CANCEL'); end; end;
2. 匿名回调函数
这种写法适合代码量少的,多了就比较乱,还是标准的看着习惯。
procedure TMainForm.UniButton6Click(Sender: TObject); begin MessageDlg('Dialog3', mtConfirmation, mbYesNo, procedure(Res: Integer) begin case Res of mrYes : MessageDlg('Dialog4', mtConfirmation, mbYesNo, procedure(Res: Integer) begin case Res of mrYes : UniMemo1.Lines.Add('DResult: YES'); mrNo : UniMemo1.Lines.Add('DResult: NO'); end; end ); mrNo : UniMemo1.Lines.Add('DResult: NO'); end; end ); end;