![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Нажатие Bitbtn с клавиатуры [D5, XP]
Андрей_1 © (2008-09-17 13:32:00)В проге есть кнопки Bitbtn. Надо чтобы была возможность нажатия их с клавиатура клавишами 1,2,3,4,5......9. Подскажите пожалуйста!!!
[i2e] (2008-09-18 15:21:00) [1]
procedure TMDIChild.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var ...;
begin
if Shift=[ssShift] then
begin
case Key of
VK_UP: ...;
VK_DOWN: ...;
VK_LEFT: ...;
VK_RIGHT: ...;
end;
Exit;
end;
//
if (chr(Key)='O') then // Открыть последний файл
begin
MainForm.SpeedButton5.OnClick(Sender); // <--- нажатие кнопки
end;
//
if (chr(Key)='R') then // Rotate - вертеть компонент связь
begin
MainForm.fRotateComp := True;
FormActivate(Sender);
end;
case Key of
VK_UP: begin // стрелка вверх
...
end;
и т.д.
может поможет?
кусок точно рабочий. проверено. SpeedBtn или BitBtn - разницы нет.
{RASkov} (2008-09-18 11:43:00) [2]> [28] Андрей_1 © (18.09.08 07:24)
Да чтож не везуха-то какая :(
Vlad Oshin (2008-09-18 09:40:00) [3]
> где ты это чудо написал
на стене, в туалете :)
> что оно по-твоему должно делать...
отвлекать от процесса, чего же еще?
-------
1. form.KeyPreview=?
2. Всю процедуру, от шапки, нельзя показать?
Может ты ее на ConstrainedResize повесил :)
Dennis I. Komarov (2008-09-18 09:18:00) [4]А теперь раскажи где ты это чудо написал, и что оно по-твоему должно делать...
Андрей_1 (2008-09-18 07:24:00) [5]Написал так:
if (FindComponent('Bitbtn' + Key) is tBitBtn)
then Btn := tBitBtn(FindComponent('Bitbtn' + Key) );
ShowMessage('Key');
Comp := FindComponent('Bitbtn' + Key);
if (Comp is TBitBtn) then
TBitBtn(Comp).Click;
Но сообщения "ShowMessage('Key')" не по является. Видимо не определяется нажптие клавиши.
Vlad Oshin (2008-09-17 16:57:00) [6]кстати, хотел спросить в чем разница
T1(T2).prop:=
и
(T2 as T1).prop:=
почти спросил, но потом полез в CPU, понял. Не стирать же :)
tb=class(tButton)
private
q:string;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
b:tb;
procedure SetCaption1(var B:tObject);
begin
if (B is tButton)
then tButton(B).Caption:='111';
{
Unit1.pas.36: then tButton(B).Caption:='111';
00458074 8B03 mov eax,[ebx]
00458076 BA8C804500 mov edx,$0045808c
0045807B E8F41BFEFF call TControl.SetText
}
end;
procedure SetCaption2(var B:tObject);
begin
if (B is tButton)
then (B as tButton).Caption:='222';
{
Unit1.pas.48: then (B as tButton).Caption:='222';
004580A4 8B03 mov eax,[ebx]
004580A6 8B15F07F4200 mov edx,[$00427ff0]
004580AC E85BB9FAFF call @AsClass
004580B1 BAC8804500 mov edx,$004580c8
004580B6 E8B91BFEFF call TControl.SetText
}
end;
begin
b:=tb.Create(form1);
b.Parent:=form1;
b.Left:=1;
b.Top:=1;
b.Visible:=true;
SetCaption1(tObject(b));
ShowMessage('');
SetCaption2(tObject(b));
end;
------------------------------------------------------------
tb=class(tButton)
private
q:string;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
b:tb;
procedure SetCaption1(var B:tObject);
begin
if (B is tButton)
then tLabel(B).Caption:='111';
//ок! для все что имеет Caption
end;
procedure SetCaption2(var B:tObject);
begin
if (B is tButton)
then (B as tLabel).Caption:='222';//invalid
end;
begin
b:=tb.Create(form1);
b.Parent:=form1;
b.Left:=1;
b.Top:=1;
b.Visible:=true;
SetCaption1(tObject(b));
ShowMessage('');
SetCaption2(tObject(b));
end;
----------
clickmaker (2008-09-17 16:32:00) [7]var Comp: TComponent;
Comp := FindComponent('Bitbtn' + Key);
if (Comp is TBitBtn) then
TBitBtn(Comp).Click;
Андрей_1 (2008-09-17 16:29:00) [8]Тут ошибок не появляется, но
if (FindComponent('Bitbtn' + Key) is tBitBtn)
then Btn := tBitBtn(FindComponent('Bitbtn' + Key) );
Btn.Click;
нет события нажатия на соответствующую BitBtn
Vlad Oshin (2008-09-17 16:13:00) [9]:)
а я злой
> Btn := FindComponent('Bitbtn' + Key);
>
> Ошибка: [Error] Unit1.pas(589): Incompatible types: 'TBitBtn'
> and 'TComponent'
Btn := TBitBtn(FindComponent('Bitbtn' + Key));
или
if (FindComponent('Bitbtn' + Key) is tBitBtn)
then Btn := tBitBtn(FindComponent('Bitbtn' + Key) );
или
if (FindComponent('Bitbtn' + Key) is tBitBtn)
then Btn := (FindComponent('Bitbtn' + Key) as tBitBtn);
Anatoly Podgoretsky (2008-09-17 16:09:00) [10]> Андрей_1 (17.09.2008 15:56:18) [18]
Так и есть.
Правильный$Вася (2008-09-17 16:06:00) [11]
> Стрельба наугад из за угла?
ты что, это научный метод
ТриП называется: пол-потолок-палец
{RASkov} (2008-09-17 16:02:00) [12]> Не, то то которое с моторчиком :)
:)
Наоборот)
Не, не то....
Плохиш (2008-09-17 16:01:00) [13]
> Андрей_1 © (17.09.08 15:56) [18]
Значит не судьба.
{RASkov} (2008-09-17 15:59:00) [14]> [18] Андрей_1 © (17.09.08 15:56)
Используй приведение.... Не, то то которое с моторчиком :)
Андрей_1 (2008-09-17 15:56:00) [15]Btn := FindComponent('Bitbtn' + Key);
Ошибка: [Error] Unit1.pas(589): Incompatible types: 'TBitBtn' and 'TComponent'
Anatoly Podgoretsky (2008-09-17 15:55:00) [16]> clickmaker (17.09.2008 15:23:10) [10]
IntToStr(Ord('1') - 48)) = '1'
Германн (2008-09-17 15:55:00) [17]
> Выдаёт:
>
> [Error] Unit1.pas(586): Incompatible types: 'TBitBtn' and
> 'TComponent'
>
> Сделал:
>
> Btn := FindComponent('Bitbtn' + IntToStr(Key));
>
> Выдаёт:
> [Error] Unit1.pas(589): There is no overloaded version of
> 'IntToStr' that can be called with these arguments
>
Стрельба наугад из за угла?
Андрей_1 (2008-09-17 15:49:00) [18]сделал:
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
var Btn: TBitBtn;
begin
Btn := FindComponent('Bitbtn' + IntToStr(Ord(Key) - 48));
if (Btn <> nil) then
Btn.Click;
end;
Выдаёт:
[Error] Unit1.pas(586): Incompatible types: 'TBitBtn' and 'TComponent'
Сделал:
Btn := FindComponent('Bitbtn' + IntToStr(Key));
Выдаёт:
[Error] Unit1.pas(589): There is no overloaded version of 'IntToStr' that can be called with these arguments
Германн (2008-09-17 15:30:00) [19]
> Германн © (17.09.08 15:29) [13]
Не проснулся :(
Германн (2008-09-17 15:29:00) [20]
> FindComponent('Bitbtn' + IntToStr(Ord(Key) - 48));
Bitbtn#0 - это круто :)