BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Yes/No responses in Delphi, using keyboard

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
Mike McWhinney
Guest





PostPosted: Tue Jan 27, 2004 4:59 am    Post subject: Yes/No responses in Delphi, using keyboard Reply with quote



Hello,

I am writing a program that asks the user several yes/no questions.
I thought that using a TRadioGroup with TStrings of Yes and No might
be a good way. However, one of the requirements is that the user can
use the keyboard to input responses and to quickly navigate the
screens.
I have run into some problems with using RadioGroups:

1. If I use accellerator keys (i.e. &Yes, &No) this will work for one
of
the radiogroups, but any additional radiogroups, the first radiogroup
will
take precedence.

2. I would require a keyhandler or event using TForm.FormKeyDown to
check
for the 'Y', 'N' keys. I would also have to advance the focus to the
next component on the form so that it automatically jumps to the next
question.


Is there a better component/control to use for boolean/yes&no queries?

Thanks.

Mike McWhinney
Back to top
Rob Kennedy
Guest





PostPosted: Tue Jan 27, 2004 6:03 am    Post subject: Re: Yes/No responses in Delphi, using keyboard Reply with quote



Mike McWhinney wrote:
Quote:
1. If I use accellerator keys (i.e. &Yes, &No) this will work for one
of the radiogroups, but any additional radiogroups, the first
radiogroup will take precedence.

When focus enters the radio group, set the keyboard accelerators for
those radio buttons. When focus leaves that group, clear the
accelerators. Thus only one set of radio buttons will have keyboard
shortcuts at a time. (You'll need to do a bit of testing -- random
clicking and typing -- to ensure that there isn't a way to throw off the
synchronization.)

Quote:
2. I would require a keyhandler or event using TForm.FormKeyDown to
check for the 'Y', 'N' keys.

Aren't keys with accelerators supposed to do that automatically?

Quote:
I would also have to advance the focus to the next component on the
form so that it automatically jumps to the next question.

In the OnClick event handler, set the focus to the next question.

Quote:
Is there a better component/control to use for boolean/yes&no
queries?

A list box or similar control, with three items -- blank/unanswered,
yes, and no -- should be able to handle the Y/N keys since the item that
starts the the corresponding letter should be selected automatically.
(If it's not automatic, then the feature you'd need to look for would be
type-ahead find or incremental search.)

A combo box would have a similar effect. An advantage would be that only
the selected answer would be visible. A disadvantage would be that they
often require more mouse clicks to operate.

Maybe you could use an edit box that only accepts the letters N and Y,
and upon getting one of those letters, automatically advances to the
next question.

And there's always MessageBox.

--
Rob

Back to top
Terry Russell
Guest





PostPosted: Tue Jan 27, 2004 6:52 am    Post subject: Re: Yes/No responses in Delphi, using keyboard Reply with quote



"Mike McWhinney" <eljainc (AT) ameritech (DOT) net> wrote

Quote:
Hello,

I am writing a program that asks the user several yes/no questions.
I thought that using a TRadioGroup with TStrings of Yes and No might
be a good way. However, one of the requirements is that the user can
use the keyboard to input responses and to quickly navigate the
screens.
I have run into some problems with using RadioGroups:

1. If I use accellerator keys (i.e. &Yes, &No) this will work for one
of
the radiogroups, but any additional radiogroups, the first radiogroup
will
take precedence.

2. I would require a keyhandler or event using TForm.FormKeyDown to
check
for the 'Y', 'N' keys. I would also have to advance the focus to the
next component on the form so that it automatically jumps to the next
question.


Is there a better component/control to use for boolean/yes&no queries?

There are an infinite number of ways, monkey #173,987,678 may have
typed this on day 43,772

Checkbox
rxswitch
speedbuttons toggled or grouped


e.g.

make some checkboxes
make one keydownhandler
select all those boxes
assign all to that handler ( ide sets it to all currently selected)

organise to initialise a list for the step order of controls
e.g. in constructor

nextlist:=tlist.create;
nextlist.add(checkbox1);
nextlist.add(checkbox2);
nextlist.add(checkbox3);
nextlist.add(checkbox4);
nextlist.add(checkbox5);
nextlist.add(checkbox6);
nextlist.add(checkbox7);


// here step to the next
// this could be taborder (findnextcontrol)
// but we probably want our own order

//type TexposedWincontrol=class(twincontrol);
var Nextlist:tlist;
procedure nextstep(sender:tobject);
//var next:twincontrol;
var fnord:integer;
begin
application.processmessages;
// another method to wave arms
//
next:=texposedwincontrol(Twincontrol(sender).parent).FindNextControl(twincon
trol(sender),true,true,true);
// if next <> nil then next.setfocus;

fnord:=nextlist.indexof(sender);
if (fnord = -1) or (fnord= nextlist.count-1)
then twincontrol(nextlist.items[0]).setfocus
else
twincontrol(nextlist.items[fnord+1]).setfocus;
end;


procedure TForm1.CheckBoxKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
ord('Y'),ord('y'):
begin
Tcheckbox(sender).checked:=true;
nextstep(sender);
end;
ord('N'),ord('n') :
begin
Tcheckbox(sender).checked:=false;
nextstep(sender);
end;
ord(' ') : // space toggles
begin
key:=0; // kill the space handling
Tcheckbox(sender).checked:=not Tcheckbox(sender).checked;
nextstep(sender);
end;
else
beep;
end;

end;







Back to top
AlanGLLoyd
Guest





PostPosted: Tue Jan 27, 2004 7:49 am    Post subject: Re: Yes/No responses in Delphi, using keyboard Reply with quote

In article <40160af2$0$29131$afc38c87 (AT) news (DOT) optusnet.com.au>, "Terry Russell"
<trochilus (AT) GREENEGGSoptusnet (DOT) com.au> writes:

Quote:
procedure TForm1.CheckBoxKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case key of
ord('Y'),ord('y'):
begin
Tcheckbox(sender).checked:=true;
nextstep(sender);
end;
ord('N'),ord('n') :
begin
Tcheckbox(sender).checked:=false;
nextstep(sender);
end;
ord(' ') : // space toggles
begin
key:=0; // kill the space handling
Tcheckbox(sender).checked:=not Tcheckbox(sender).checked;
nextstep(sender);
end;
else
beep;
end;


Shouldn't you really be using VK_??? constants, also OnKeyDown.Key never has a
value of Ord('y') unless you press F10 <g>.

However some early versions of Delphi did not have all the VK_??? values
declared, so you may have to do that.

Alan Lloyd
[email]alanglloyd (AT) aol (DOT) com[/email]

Back to top
Bruce Roberts
Guest





PostPosted: Wed Jan 28, 2004 8:11 pm    Post subject: Re: Yes/No responses in Delphi, using keyboard Reply with quote


"Mike McWhinney" <eljainc (AT) ameritech (DOT) net> wrote


Quote:
2. I would require a keyhandler or event using TForm.FormKeyDown to
check
for the 'Y', 'N' keys. I would also have to advance the focus to the
next component on the form so that it automatically jumps to the next
question.

theForm.ActiveControl.SelectNext;

Quote:
Is there a better component/control to use for boolean/yes&no queries?

tCheckBox is generally used for boolean states. One simply has to word the
caption appropriately. A tComboBox with style set to csDropDownList works
quite well and, with no additional coding, should do what you want, i.e.
allow the user to type Y or N. (As in all Windows apps, Tab and Shift+Tab
move field to field.)



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.