Solved

validate edit

Posted on 2004-04-09
9
332 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 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

705 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