Свой обработчик переключения между элементами на форме
03.04.2013
Для того чтобы реализовать переход от (передачу фокуса) одного valuelisteditor к другому нужно было отследить нажатие кнопок tab и enter
1 |
unit uTest; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, ValEdit, StdCtrls; type TForm1 = class(TForm) ValueListEditor1: TValueListEditor; ValueListEditor2: TValueListEditor; procedure Button1Click(Sender: TObject); private procedure CMDialogKey( var msg: TCMDialogKey ); message CM_DIALOGKEY; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.CMDialogKey(var msg: TCMDialogKey); var iActRow : integer; begin if msg.Charcode = VK_TAB then begin Form1.Caption := 'Tab Key Down!'; iActRow:= ValueListEditor1.Row; inc(iActRow); if iActRow >= ValueListEditor1.RowCount then begin ValueListEditor2.Row:= 1; ActiveControl:= nil; ActiveControl:= ValueListEditor2; end else begin ValueListEditor1.Row:=iActRow; end ; iActRow:= ValueListEditor2.Row; inc(iActRow); if iActRow < ValueListEditor2.RowCount then begin ValueListEditor2.Row:=iActRow; end; end else begin inherited; end ; end; end. |
Доделанный вариант (еще обрабатывается нажатие enter);
1 |
unit uTest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ValEdit, StdCtrls;
type
TForm1 = class(TForm)
ValueListEditor1: TValueListEditor;
ValueListEditor2: TValueListEditor;
procedure FormCreate(Sender: TObject);
procedure ValueListEditor1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ValueListEditor2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
procedure CMDialogKey( var msg: TCMDialogKey );
message CM_DIALOGKEY;
procedure prcGoNext();
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CMDialogKey(var msg: TCMDialogKey);
begin
if msg.Charcode = VK_TAB then
begin
prcGoNext();
end
else
begin
inherited;
end
;
end;
procedure TForm1.prcGoNext;
var
iActRow : integer;
begin
if ActiveControl = ValueListEditor1 then
begin
iActRow:= ValueListEditor1.Row;
inc(iActRow);
if iActRow >= ValueListEditor1.RowCount then
begin
ValueListEditor2.Row:= 1;
ActiveControl:= nil;
ActiveControl:= ValueListEditor2;
end
else
begin
ValueListEditor1.Row:=iActRow;
end
;
end
else
begin
if ActiveControl = ValueListEditor2 then
begin
iActRow:= ValueListEditor2.Row;
inc(iActRow);
if iActRow < ValueListEditor2.RowCount then
begin
ValueListEditor2.Row:=iActRow;
end;
end;
end
;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i :Integer;
begin
for i := 1 to 8 do
begin
ValueListEditor1.Strings.Values[IntToStr(i)]:=' ';
end;
for i := 8 to 12 do
begin
ValueListEditor2.Strings.Values[IntToStr(i)]:=' ';
end;
end;
procedure TForm1.ValueListEditor1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then
begin
prcGoNext();
end
else
begin
inherited;
end
;
end;
procedure TForm1.ValueListEditor2KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then
begin
prcGoNext();
end
else
begin
inherited;
end
;
end;
end.
|