お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"EnterKeyで次の項目へ移動 (手抜き支援)"





//いろいろなコンポで、「EnterKeyで次の項目へ移動」

いろいろなコンポーネントで「EnterKeyで次の項目へ移動」を
したいとき、このUnitを継承してフォームを作成すれば
TEdit,TDBEdit等もちろん、TStringGrid,TDBGridでも次のセルに移動する
様になります。
TDBLookupComboBoxの様にListが開いているときはListを閉じ、通常の状態の
ときは次の項目へ移動する等と云うことにも対応しています。
組み込まれていないコンポもこれを参考にしていただければたぶん同様にで
きるでしょう(^^;;;

以下のUnitを、継承してお使いください。

---------------------------------------------------------------
unit UnitBase2;

interface

uses
  Windows, Messages, SysUtils, Classes, Forms,
  DBGrids, DBCtrls, Grids, DBCGrids ;

type
  TFormBase2 = class(TForm)
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift:
                          TShiftState);
    private
      { Private 宣言 }

    public
      { Public 宣言 }
  end;

var
  FormBase2: TFormBase2;

implementation

{$R *.DFM}

{ FormKeyDown }
procedure TFormBase2.FormKeyDown(Sender: TObject; var Key: Word,
                                 Shift: TShiftState);
begin
  if not ((ActiveControl is TDBGrid)
       or (ActiveControl is TDBLookupListBox)
       or (ActiveControl is TDBLookupComboBox)
       or (ActiveControl is TStringGrid)
       or (ActiveControl is TDBCtrlGrid)) then begin
    if (ActiveControl is TDBLookupComboBox)  then  begin
      if not TDBLookupComboBox(Sender).ListVisible  then  begin
        Exit;
      end;
    end;
    Case Key Of
      VK_Up:  Begin
          Perform(WM_NEXTDLGCTL, 1, 0);
          Key := 0;
        End;
      VK_Down:  Begin
          if  not (ssALT in Shift)  then  begin
            Perform(WM_NEXTDLGCTL, 0, 0);
            Key := 0;
          end;
        End;
    End;
  end;
end;

{FormKeyPress}
procedure TFormBase2.FormKeyPress(Sender: TObject; var Key: Char);
begin
  If Key = Chr(VK_Return) then Begin
    If ActiveControl is TDBGrid Then  begin
      Key := #0;
      With TDBGrid(ActiveControl) Do  Begin
        If SelectedIndex = FieldCount - 1 Then  Begin
          If DataSource.DataSet <> Nil Then begin
            DataSource.DataSet.Next;
            If DataSource.DataSet.Eof Then
              DataSource.DataSet.Append;
          end;
          SelectedIndex := 0;
        End
        Else
          SelectedIndex := SelectedIndex + 1;
      End
    end
    else begin
      Key := #0;
      Perform(WM_NEXTDLGCTL, 0, 0);
    end;
  end;
end;

end.
---------------------------------------------------------------

TDBLookupListBoxだけはTestしていません(^^;
また、TComboBox等は使用していないので組み込んでいません。

--- 2000/10/12(Thu) 20:19pm S.S.Labo (GHF03343) ---
 


- FDELPHI  MES(16):玉石混淆みんなで作るSample蔵【見本蓄積】 00/10/13 -

Original document by S.S.Labo        氏 ID:(GHF03343)


ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum