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

Convert The First Letter In Any Word To A Capital

By , About.com Guide

Here's how to convert the first letter in an edit box (Edit1) to a capital:

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.Button1Click(Sender: TObject) ;
var
  GetString : string;
  GetLength : Integer;
  I : Integer;
  T : String;
begin
  if edit1.SelLength > 0 then
    GetString:= Edit1.Seltext
  else GetString:= Edit1.Text;
  GetLength:= Length(GetString) ;
  if GetLength>0 then begin
   for I:= 0 to GetLength do begin
    if (GetString = ' ') or (I=0) then begin
     if GetString[I+1] in ['a'..'z'] then begin
      T:=GetString[I+1];
      T:=UpperCase(T) ;
      GetString[I+1]:=T[1];
     end;
    end;
   end;
   if edit1.Sellength>0 then
     Edit1.Seltext:=GetString
   else Edit1.Text:=GetString;
  end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Delete folders recursively
« Search And Replace

About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

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