Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.10.16;
Скачать: CL | DM;

Вниз

Опрос клавиатуры   Найти похожие ветки 

 
Eugene_ ©   (2003-10-05 11:00) [0]

Здравствуйте!
Сразу говорю вопрос немного банальный, по-этому сразу извините.
Есть такой обработчик нажатий клавиш:

procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key=VK_UP then
if DBGrid1.DataSource=DataSource1 then begin
Key:=0;
Table.Prior;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
if not VarIsNull(Table.FieldByName("Numb").Value) then
Curr:=Table.FieldValues["Numb"]
else
Curr:=Table.RecNo;
TestClick();end
else if DBGrid1.DataSource=DataSource2 then begin
Key:=0;
Query.Prior;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
if not VarIsNull(Query.FieldByName("Numb").Value) then
Curr:=Query.FieldValues["Numb"]
else
Curr:=Query.RecNo;
TestClick();end
else if DBGrid1.DataSource=DataSource3 then begin
Key:=0;
Table1.Prior;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
if not VarIsNull(Table1.FieldByName("Numb").Value) then
Curr:=Table1.FieldValues["Numb"]
else
Curr:=Table1.RecNo;
TestClick();
end;
if Key=VK_DOWN then
if DBGrid1.DataSource=DataSource1 then begin
Key:=0;
Table.Next;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
if not VarIsNull(Table.FieldByName("Numb").Value) then
Curr:=Table.FieldValues["Numb"]
else
Curr:=Table.RecNo;
TestClick();end
else if DBGrid1.DataSource=DataSource2 then begin
Key:=0;
Query.Next;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
if not VarIsNull(Query.FieldByName("Numb").Value) then
Curr:=Query.FieldValues["Numb"]
else
Curr:=Query.RecNo;
TestClick();end
else if DBGrid1.DataSource=DataSource3 then begin
Key:=0;
Table1.Next;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
if not VarIsNull(Table1.FieldByName("Numb").Value) then
Curr:=Table1.FieldValues["Numb"]
else
Curr:=Table1.RecNo;
TestClick();
end;
if Key=VK_HOME then
if DBGrid1.DataSource=DataSource1 then begin
Table.First;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
Curr:=Table.RecNo;
TestClick();end
else if DBGrid1.DataSource=DataSource2 then begin
Query.First;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
Curr:=Query.RecNo;
TestClick();end
else if DBGrid1.DataSource=DataSource3 then begin
Table1.First;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
Curr:=Table1.RecNo;
TestClick();
end;
if Key=VK_END then
if DBGrid1.DataSource=DataSource1 then begin
Table.Last;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
Curr:=Table.RecNo;
TestClick();end
else if DBGrid1.DataSource=DataSource2 then begin
Query.Last;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
Curr:=Query.RecNo;
TestClick();end
else if DBGrid1.DataSource=DataSource3 then begin
Table1.Last;
DBGrid1.Options:=[dgTitles,dgColumnResize,dgColLines,dgRowLines,dgTabs,dgRowSelect,dgAlwaysShowSelection];
Curr:=Table1.RecNo;
TestClick();
end;
if (Key=65) and (ssAlt in Shift) then
N9Click(self);
if Key=115 then
N4Click(self);
if Key=45 then
if (HiWord(GetKeyState(VK_LMENU))<>0)and(HiWord(GetKeyState(VK_RCONTROL))<>0) then
Merge()
else if ssCtrl in Shift then begin
if MainForm.DBGrid1.DataSource=MainForm.DataSource2 then begin
MessageBox(Application.Handle,"Выйдите из режима поиска!","База данных",MB_ICONWARNING);
Exit;
end;
EditInfoForm.ShowModal;end
else
N2Click(self);
if Key=69 then
if (HiWord(GetKeyState(VK_RCONTROL))<>0) and (HiWord(GetKeyState(VK_LMENU))<>0) then
SaveToFile();
if (Key=112) and (ssAlt in Shift) then
CD1Click(self);
if (Key=113) and (ssAlt in Shift) then
HDD1Click(self);
if Key=35 then
if (HiWord(GetKeyState(VK_LMENU))<>0)and(HiWord(GetKeyState(VK_RCONTROL))<>0) then
ReIndex(MainForm.Table1);
if (Key=46) and (ssCtrl in Shift) then Key:=0;
if Key=120 then
N25Click(self);
end;


и в этот код будут добавляться еще новые коды клавиш.
Можно как-то сократить количество if ... then?

Заранее спасибо ...


 
Real ©   (2003-10-05 11:07) [1]

Для начала - оптимизируй структуру - сплошные повторы и вложенные ИФ-ы. Иф - всегда можно заменить Кэйсом, но сильно суть от этого не изменится



Страницы: 1 вся ветка

Текущий архив: 2003.10.16;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.027 c
4-51554
i-s-v
2003-08-11 01:51
2003.10.16
Как читать строки из реестра


4-51548
V3L0M
2003-08-12 22:53
2003.10.16
как получить handle speedbutton а в чужой программе


14-51455
Aristarh
2003-09-29 16:40
2003.10.16
Британия чем провинилась?


3-51099
domenicas
2003-09-25 15:16
2003.10.16
SQL Server 2000 ???


4-51556
Jack
2003-08-11 14:52
2003.10.16
Как проверить занят ли файл или нет?