⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basedialogime.pas

📁 一个MRPII系统源代码版本
💻 PAS
字号:
unit BaseDialogIme;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  BaseIme, StdCtrls,grids,db,dbgrids,extCtrls;

Type
  TFrm_BaseDialogIme = Class(TFrm_BaseIme)
    btn_ok: TButton;
    btn_Cancel: TButton;
    edt_tmp: TEdit;
    Label1: TLabel;
    procedure btn_okClick(Sender: TObject);virtual;
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);virtual;
    procedure FormKeyPress(Sender: TObject; var Key: ChAr);virtual;
    procedure check(sender:tobject);virtual;
    procedure edt_tmpExit(Sender: TObject);virtual;
    procedure btn_CancelClick(Sender: TObject);virtual;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    upkey:boolean;
  public
    { Public declarations }
  protected
    checkResult:boolean;
    okbutton:boolean;
    controlName:string;
    procedure groupenter(sender:tobject);
  end;

var
  Frm_BaseDialogIme: TFrm_BaseDialogIme;

implementation

{$R *.DFM}

procedure TFrm_BaseDialogIme.btn_okClick(Sender: TObject);
begin
  if not (activecontrol is tbutton) then
    btn_ok.setfocus
  else
    check(sender);
end;

procedure TFrm_BaseDialogIme.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  upkey:=(key=vk_up);
  case key of
    vk_eScApe:
      if Btn_Cancel.visible then
        Btn_CancelClick(Sender);
    vk_return:
    begin
      if ((activecontrol is tcombobox) and ((sSalt in shift) or (activecontrol as tcombobox).droppeddown)) then
        exit;
      if (activecontrol is tcustomgrid) then exit;
      selectnext(activecontrol as twincontrol,True,True);
      key:=0;
    end;
    vk_Down,vk_up:
    begin
      if ((activecontrol is tcombobox) and ((sSalt in shift) or (activecontrol as tcombobox).droppeddown)) then
        exit;
      if (activecontrol is tcustomdbgrid) then
      if not ((key=vk_up) and (tcustomdbgrid(activecontrol).dataSource.dataset.bof)) or
         ((key=vk_Down) and (tcustomdbgrid(activecontrol).dataSource.dataset.eof)) then
        exit;
      if (activecontrol is tstringgrid) then
        if ((key=vk_up) and ((activecontrol as tstringgrid).row<>1)) or ((key=vk_Down) and ((activecontrol as tstringgrid).rowCount-1<>(activecontrol as tstringgrid).row)) then
          exit;
      if (activecontrol is tListbox) then
        if ((key=vk_up) and ((activecontrol as tListbox).Itemindex>0)) or ((key=vk_Down) and ((activecontrol as tListbox).Items.Count-1<>(activecontrol as tListbox).Itemindex)) then
          exit;
      selectnext(activecontrol as twincontrol,key=vk_Down,True);
      key:=0;
    end;
  end;
end;

procedure TFrm_BaseDialogIme.FormKeyPress(Sender: TObject; var Key: ChAr);
begin
  if (word(key)=vk_return) then
  begin
//    key:=#0;
  end;
end;

procedure TFrm_BaseDialogIme.edt_tmpExit(Sender: TObject);
begin
  try
    if (activecontrol=btn_Cancel) or
       ((activecontrol.tabOrder<(sender as twincontrol).tabOrder) and
        (activecontrol.Parent=(sender as twincontrol).Parent)) then
      exit;
  except
    exit;
  end;
//  if (activecontrol=btn_ok) then
//  begin
//    btn_ok.click;
//    exit;
//  end;
  check(sender);
  if not checkResult then
    activecontrol:=(sender as twincontrol);
end;

procedure TFrm_BaseDialogIme.check(Sender: TObject);
begin
  okbutton:=False;
  checkResult:=True;
  if sender is twincontrol then
  begin
    if sender is tbutton then
    begin
      if ((sender as tbutton).Name='btn_ok') then
        okbutton:=True;
    end
    else
      controlName:=(sender as twincontrol).Name;
  end;

  if (sender is twincontrol) or (activecontrol is tbutton) then
  begin
    if activecontrol is tbutton then
    begin
      if (activecontrol as tbutton).Name='btn_ok' then
        okbutton:=True;
    end
    else
      controlName:=(sender as twincontrol).Name;
  end
  else
    exit;
end;

procedure TFrm_BaseDialogIme.btn_CancelClick(Sender: TObject);
begin
  modalResult:=mrCancel;
end;

procedure TFrm_BaseDialogIme.FormCreate(Sender: TObject);
var
  i:integer;
begin
  inherited;
  upkey:=False;
  for i:=0 to controlCount-1 do
  begin
    if (controls[i] is tgroupbox) then
      tgroupbox(controls[i]).onenter:=groupenter
    else if (controls[i] is tpanel) then
      tpanel(controls[i]).onenter:=groupenter
    else if (controls[i] is tRadiogroup) then
      tRadiogroup(controls[i]).onenter:=groupenter;
  end;
end;

procedure TFrm_BaseDialogIme.groupenter(sender:tobject);
var
  controlList:tList;
  i:integer;
begin
  controlList:=tList.Create;
  twincontrol(sender).gettabOrderList(controlList);
  if upkey then
    for i:=controlList.Count-1 downto 0 do
    begin
      if twincontrol(controlList[i]).canfocus then
      begin
        tedit(controlList[i]).setfocus;
        exit;
      end;
    end
  else
    for i:=0 to controlList.Count-1 do
    begin
      if twincontrol(controlList[i]).canfocus then
      begin
        tedit(controlList[i]).setfocus;
        exit;
      end;
    end;
  controlList.free;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -