Link to home
Start Free TrialLog in
Avatar of mfrost03
mfrost03

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of pjenglund
pjenglund

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DaFox
DaFox

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
Avatar of kretzschmar
TEdit also TDBEdit has a CharCase-Property

just set it to ecUpperCase

meikl ;-)
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
> 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
Avatar of mfrost03

ASKER

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!