Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

validate edit

Posted on 2004-04-09
9
Medium Priority
?
342 Views
Last Modified: 2010-04-05
I wish to have an dbedit field that will change the first character of each word to uppercase.
0
Comment
Question by:johnshailes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 1

Expert Comment

by:psycho_cat_69
ID: 10793099
on the OnExit event of your DBEdit you can do this

DBEdit1.Text := UPPERCASE(copy(DBEdit1.Text,1,1)) + copy(DBEdit1.Text,2,length(DBEdit1.Text));
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 750 total points
ID: 10793442
This method will change the first character of each word to uppercase  as you type them, not waiting for you to exit.

Place this code in the OnKeyPress event of each of your TDBEdits you want this behavior in

 with Sender as TDBEdit do
  if (Text = '') OR (Text[SelStart] = ' ') OR (SelLength = Length(Text)) then
   if Key in ['a'..'z'] then  Key := UpCase(Key);

SHane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10793896
What is differrent in my solution
 - converts all characters to uppercase - not only this from range a - z
 - proper reaction for space insert/ delete

Question
 Should change other letters to lower case?

procedure TForm1.DBEdit1Change(Sender: TObject);
var
  i: integer;
  str: string;
  p: integer;
begin
 with Sender as TDBEdit do
   begin
   p := SelStart;
   str := Text;
   for i := 1 to Length(str) do
     begin
     if i = 1 then
       str[1] := AnsiUpperCase(str[1])[1]
     else if str[i-1] = ' ' then
       str[i] := AnsiUpperCase(str[i])[1]
     else
       str[i] := AnsiLowerCase(str[i])[1]
     end;
   Text := str;
   SelStart := p;
   end;
end;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10793921
Mokule, i believe his request was for
 "first character of each word to uppercase"

and my solution above also allows for backspace, and spaces

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10793999
If you use my solution of Mokule solution, you can use the same solution for all Edits

by changing the typecast

example

with Sender as TDBComboBox do
  if (Text = '') OR (Text[SelStart] = ' ') OR (SelLength = Length(Text)) then
   if Key in ['a'..'z'] then  Key := UpCase(Key);


Shane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10794074
Shane,
But Your solution improperly react for inserting spaces.
If You write Unitedstates and go back to insert space it don't change for United States but leaves United states. My solutiolution on the other hand disallows writing McDonald and should be corrected if it is necessary.

Marek
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10794149
Hmm, you may be right, but i dont believe there will ever be a need (and if so, just back up alittle farthur). I use my solution in many applications - As a matter of fact, its used in Game Console Manager (which is currently used in 94 gaming centers nationwide). Out of many of the bugs or fixes I have had to complete, no one has ever mentioned that.....

However, good find....

Shane
0
 
LVL 17

Expert Comment

by:mokule
ID: 10794225
Shane,

Pay attention that his request didn't mention about typing. It is possible that he has already some data in database and only want to display it with big letters. I'm only speculating, but one never knows.

Marek
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10794261
Good point!

Shane
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question