Delphi Programming

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

Convert the First Character in an Edit Box to Uppercase

By Zarko Gajic, About.com

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

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Delphi Programming

  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.