www.pudn.com > RxRichEdit2.0.rar > ModalForm.pas
{$IFNDEF _DEBUG_}
{$D-}
{$ENDIF}
unit ModalForm;
interface
uses
Windows, Messages, SysUtils, Classes, Forms, Controls, Menus, ExtCtrls,
StdCtrls, Buttons, MyFormDivider, BaseForm, Grids, DBGrids, DB;
type
TFrmModal = class(TFrmBase)
btnCancel: TSpeedButton;
btnOk: TSpeedButton;
btnHelp: TSpeedButton;
DividForm: TMyFormDivider;
procedure FormCreate(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure btnOkClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
class function Execute: TModalResult; virtual; ///运行对话框
end;
implementation
{$R *.DFM}
procedure TFrmModal.FormCreate(Sender: TObject);
begin
inherited;
///删除改变大小控制菜单,模态对话框不允许改变大小
DeleteMenu(GetSystemMenu(Handle, False), SC_SIZE, MF_BYCOMMAND);
DividForm.Caption := Application.Title;
end;
procedure TFrmModal.btnCancelClick(Sender: TObject);
begin
inherited;
ModalResult := mrCancel; ///返回取消
end;
procedure TFrmModal.FormKeyPress(Sender: TObject; var Key: Char);
begin
inherited;
if ActiveControl is TDBGrid then ///如果是DBGrid
if (ActiveControl as TDBGrid).DataSource.State = dsEdit then
begin ///如果正在DBGrid中进行修改
if Key<>#13 then exit; ///如果不是按下回车,退出
ActiveControl.Perform(WM_KEYDOWN, VK_TAB, 0); ///按下回车则跳到下一个列
Key:=#0;
end;
if Key = #13 then ///按下回车,相当于确定
begin
if ActiveControl is TCustomMemo then exit;
Key := #0;
if btnOk.Enabled then BtnOk.Click;
end
else if Key = #27 then ///按下Esc,取消
if btnCancel.Enabled then btnCancel.Click;
end;
class function TFrmModal.Execute: TModalResult;
begin
inherited;
with Self.Create(Application) do ///创建,并且显示窗体
try
Result := ShowModal;
finally
Free;
end;
end;
procedure TFrmModal.btnOkClick(Sender: TObject);
begin
inherited;
ModalResult := mrOK; ///返回OK
end;
end.