Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unchecking Checkboxes

Status
Not open for further replies.

ColinTod

Programmer
Oct 16, 2006
19
NZ
Hi All,

I have a wierd problem that I can't work out. I am putting together a program to handle attendances and payment details for a martial arts club.

I have a form (Martial) that has the following:
- A DB_Grid (DBG_Name) that populates with a list of names from an interbase DB.
- A checkbox (CB_Attended)
- A checkbox (CB_Payment)
- A procedure called "UpdateUser" that loads all student information onto the form. It also moves the focus to CB_Attended.
- A procedure called "Attended" which performs various things depending on weather the CB_Attend is ticked or unticked. include moving the focus to CB_Payment.
- A procedure called "MakePayment" that adds or subtracts payment details.

A user can click on a name in the grid (Calls "UploadUser") and then press the space bar twice to attend and pay the student.
Everything seems to work perfectly except for the fact that a tick does not show in the 2 check boxes. If I click off and then back onto the name the tick's show up ("UploadUser" checks whether the students has attended/payed and sets checked to true/false)

procedure TMartial.CB_AttendedKeyPress(Sender: TObject; var Key: Char);
begin
if key = ' ' then
begin
if CB_Attended.Checked then
CB_Attended.Checked := false
else
CB_Attended.Checked := true;
Attended;
end;
end;

procedure TMartial.CB_PaymentKeyPress(Sender: TObject; var Key: Char);
begin
if key = ' ' then
begin
if CB_Payment.Checked then
CB_Payment.Checked := false
else
CB_Payment.Checked := true;
MakePayment;
end;
end;

Any help would be appreciated. I've spent 2 days on this as it is.

Colin
 
I would suggest to use the OnClick event of the checkbox

Code:
procedure TMartial.CB_AttendedClick(Sender: TObject);
begin
  if CB_Attended.Checked then Attended;
end;

by the way your procedures attended and MakePayment while always be executed regardless the state of the checkboxes or you need to:
Code:
else
  begin
    CB_Payment.Checked := true;
    MakePayment;
  end;



Steven
 
use the onclick event like Steven said. the toggling is automatic when clicked with the mouse or pressed with space.

I would suggest adding a boolan variable to the
attended and MakePayment procedures:

Code:
procedure TMartial.Attended(DoAttend : Boolean);
begin
 if DoAttend then
  UserWillAttend
 else
  UserWillNotAttend;
end;

procedure TMartial.CB_AttendedClick(Sender: TObject);
begin
 Attended(CB_Attended.Checked);
end;

Cheers,
Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Hi, Thanks for that but I already tried using onclick and although it fixed the problem described above something even worse happens.
When the user uses the arrow key's to go from one name on the list to the next the software runs the attended procedure automaticly. I can't work out why. Thats why I reverted back to the current option.
By the way, thanks for the extra hints.

Colin
 
Hi again,
I think I should expand on the situation for more clearity.
The modification I am making is to deal with a bar code scanner. They want to give each student a barcode so that when they come into class they can scan the code and find the student quickly.
A barcode will look something like:
%000004567
When the code detects the "%" it sets the focus to the scan code edit box:

procedure TMartial.FormKeyPress(Sender: TObject; var Key: Char);
begin
if Key ='%' then Edit1.SetFocus;
end;

When it detects the enter using the following it converts the text to an integer and then searches for the student using his liscence number, then sets the focus to CB_Attended.
procedure TMartial.Edit1KeyPress(Sender: TObject; var Key: Char);
var LicenseStr : string;
LicenseNo : integer;
begin
if Key = #13 then
begin
LicenseStr := Edit1.Text;
Edit1.Text := '';
if LicenseStr[1] = '%' then
Delete(LicenseStr, 1, 1);
LicenseNo := StrToInt(LicenseStr);
DS_Query1.DataSet.First;
while (DS_Query1.DataSet['License_No'] <> LicenseNo) and not DS_Query1.DataSet.Eof do
DS_Query1.DataSet.Next;
if DS_Query1.DataSet['License_No'] = LicenseNo then
begin
UpdateUser;
if CB_Attended.Enabled then
CB_Attended.SetFocus
else
if CB_Payment.Enabled then
CB_Payment.SetFocus;
end
else
begin
MessageDlg('No Such License Number!', mtInformation, [mbOk], 0);
Edit1.Text := LicenseStr;
end;
end;
end;

when I tested this out using onclick every student it scrolled through became attended(or unattended).

I know that this is not the most efficient coding but I am not a profesional. I only do this as a hobby.

Colin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top