1. Home
  2. Computing & Technology
  3. Delphi Programming

Convert the First Character in an Edit Box to Uppercase

By , About.com Guide

When users enter data, they often need to format it in a standard way. You can't depend on the user to do it, so the best bet is to make your program do the formatting itself.

For example, if the user types a name in all lowercase letters, the program could automatically convert the first character in the first and last names to uppercase letters.

Add the following code to the OnKeyPress event for the Edit1 component:

~~~~~~~~~~~~~~~~~~~~~~~~~
with Sender as TEdit do
    if (SelStart = 0) or
       (Text[SelStart] = ' ') then
          if Key in ['a'..'z'] then
             Key := UpCase(Key) ;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Using the RunOnce Registry Key
« Show/Hide the TaskBar in Windows

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 1999 Delphi Tips
  7. Convert the First Character in an Edit Box to Uppercase

©2009 About.com, a part of The New York Times Company.

All rights reserved.