Converting string to all upper case

I need to make sure that a user input is in all upper case for a form I am creating. How can I ether force the input as upper case or convert a string value into all upper case.


Thanks in advance

Mike
mfrost03Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pjenglundCommented:
Try this function:

function UpperCase(const S: string): string;

Example:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit2.Text := Uppercase(Edit1.Text);
  {
   Edit2.Text will be the text in Edit1

end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DaFoxCommented:
Hi Mike.

Use UpperCase() to convert the string after the user input or use the OnKeyDown/Press event to force the user to input capital letters.

Markus
0
kretzschmarCommented:
TEdit also TDBEdit has a CharCase-Property

just set it to ecUpperCase

meikl ;-)
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

DaFoxCommented:
Okay, if pjenglund already mentioned that I'll provide a way for my second suggestion. ;-)

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  // allow backspace and capital letters
  if not (Key in [#8, #65..#90]) then Key := #0;
end;

Markus
0
DaFoxCommented:
> TEdit also TDBEdit has a CharCase-Property

Yep;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if (Key in [#97..#122]) then Key := Char(Ord(Key) - 32);
end;

Just kidding.
If you're using a TEdit set CharCase to UpperCase and that's it. I forgot about that, sorry...

Markus
0
mfrost03Author Commented:
Thanks! Both answers are correct, but this allows me to control when the test is in uppercase or when it is in Normal input.  

Just for Kicks I was also trying this to do a case update on each character in the string.

var

Cap: String;
i: Integer;

Begin
  cap1 := Edit1.Text;

  for i := 1 to Length(cap1) do
     cap1[i] := UpCase(cap1[i]);
  Edit1.Text := cap1;
End;

Thanks A Bunch!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.