|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Strange Checkbox Problem
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. I use SQL to populate the grid with student names. I have provided some filters. Everything seems to be working fine. Now they have purchased a barcode scanner and want to give each student a barcode (containing the student Licsence #) so that when they come into class they can scan the code and find the student quickly. A barcode will look something like:- %000004567 The modification I am making is to deal with the bar code scanner. The concept is that the user can scan a barcode (finding the student) and the hit the space bar twice to attend and pay the student. When the code detects the "%" on the barcode 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 at the end of the barcode it converts the text to an integer and then searches for the student using his liscence number. UpdateUser loads all the Student info Focus is then set 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 the space bar is pressed the Attended procedure is run and focus is moved to CB_Payment(this happens at the end of the Attended procedure). 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; 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 ("UpdateUser" checks whether the students has attended/payed and sets checked to true/false) I origionaly used the onclick rather than KeyPress, although it fixed the problem, it produced an even worse problem. When the user used the arrow key's to go from one name on the list to the next the software runs the attended procedure automatically. When a barcode was read it would scan the list and every student it scrolled through became attended(or unattended). I can't work out why, its not called anywhere in UpDateUser. Thats why I reverted back to the current option. I know that this is not the most efficient coding but I am not a profesional. I only do this as a hobby. and for my Martial arts club. I hope someone can help here. Colin |
|
#2
|
|||
|
|||
|
Two questions:
1. a. Have you stepped through the code to make sure the lines of code that change the checked value are actually being called? b. If they are, are you sure it is not being called twice and reversing the effect? 2. If they are, does adding an: Application.ProcessMessages; call after it make any difference? Clive |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Delphi Programming > Strange Checkbox Problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|