Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Converting string to all upper case

Posted on 2003-03-27
6
Medium Priority
?
245 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:mfrost03
6 Comments
 

Accepted Solution

by:
pjenglund earned 200 total points
ID: 8219574
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
 
LVL 6

Expert Comment

by:DaFox
ID: 8219576
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8219597
TEdit also TDBEdit has a CharCase-Property

just set it to ecUpperCase

meikl ;-)
0
Independent Software Vendors: 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 6

Expert Comment

by:DaFox
ID: 8219613
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
 
LVL 6

Expert Comment

by:DaFox
ID: 8219657
> 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
 

Author Comment

by:mfrost03
ID: 8219945
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

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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…
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…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

578 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