Solved

validate edit

Posted on 2004-04-09
9
327 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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