Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old April 24th, 2008, 05:46 PM
ColinTod ColinTod is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 1 ColinTod User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 48 m 35 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old April 28th, 2008, 07:34 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 703 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 16 h 44 m 49 sec
Reputation Power: 12
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Strange Checkbox Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway