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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query/Problem regarding Onchange event. 2

Status
Not open for further replies.

CHeighlund

Programmer
Jun 11, 2007
163
US
I am attempting to write a program designed to interface with a database. Part of the program needs to permit the users to enter tracking numbers in the database, and these tracking numbers need to fit a specific pattern. A pair of maintenance programs expect this tracking number to be in all caps so they can match the copy in this particular db table to other related tables. However, I'm running into a rather unusual problem with this.

In the segment where the tracking number can be entered, I've got the following line:
Code:
lbdtCntrct_Id.Text := UpperCase(lbdtCntrct_ID.Text);
It was my understanding that this would automatically convert anything in the labeled edit box to uppercase values where applicable. (No uppercase 2, for example.) While the command does this, it or something else is also pointing the cursor back at the beginning of the labeled edit field with each change, such that attempting to type in, say, the word 'guggenheim' would result in a nicely capitalized entry of 'MIEHNEGGUG'. I have no clue what is causing this; it may be something in my code, it may be a setting somewhere on my machine (running Windows XP, for reference). Has anyone ever had this kind of problem here before, and if so, what needs to be done to correct it?
 
My first guess was that the machine may be set up for different languages at least one of which reads from right to left. I'd suggest trying to run the program on another machine (preferably in a different environment) to see if the issue is with your program or machine.

After that, tell us what events are attached to the edit control.
 
thats normal if you put it in the on keypress event.

the textbox has a CharCase property set it to ecUpperCase.

Aaron
 
If using OnKeyPress, it has to be like this:
Code:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  Key:= Upcase(Key)
  //DONT USE: Edit1.Text:= UperCase(Edit1.Text);
end;

But as Aaron suggested, that works and you won't need an OnKeyPress event.

Good call Aaron, I'd never noticed the CharCase propery.

Roo
Delphi Rules!
 
Thank you to aaronjme; shifting the CharCase property created exactly the result I wanted.

@roo0047:
The event was the labeled edit box's 'on change' event, not the 'on keypress' event. I'm not sure if that would change anything, but since the issue is now moot, I guess it doesn't matter.

Thanks to everyone for your assistance.
 
My 2 cents:

be aware that changing text in the OnChange event will fire this event again!! (in your case the second time the event is fired the text stays the same as it is already in uppercase).

Input processing is usually done in OnKeyDown or OnKeyPress Events. The OnChange Event is used to change other components that rely on the contents of your TEdit component, not for the component itself.

anyway Aaron gave the correct solution so star for him!

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top