Solved

validate edit

Posted on 2004-04-09
9
323 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
  • 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 250 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

939 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now