Solved

validate edit

Posted on 2004-04-09
9
322 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 11

Expert Comment

by:shaneholmes
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Good point!

Shane
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

12 Experts available now in Live!

Get 1:1 Help Now