Author: Tomas Rutkauskas
Does anyone have a routine for uppercasing only the first letter of each word the
user typed in an edit control - especially a combo box. I've experimented with the
mask property for the dataset field but am not having any luck.
Answer:
1 2 procedure TForm1.ComboBox1Change(Sender: TObject);
3 var4 s, TempString: string;
5 Cnt, temp: integer;
6 begin7 s := ComboBox1.Text;
8 temp := ComboBox1.SelStart;
9 if s <> '' then10 begin11 for Cnt := 1 to Length(s) do12 begin13 if (Cnt = 1) or (s[Cnt - 1] in [' ', ', ', ' ;']) then{or others here}14 begin15 TempString := s[Cnt];
16 s[Cnt] := AnsiUpperCase(TempString)[1];
17 end;
18 end;
19 ComboBox1.Text := s;
20 end;
21 ComboBox1.SelStart := temp;
22 end;
I strongly recommend to use the AnsiUpperCase function, if there's any possibility that non-English words may ever be entered into your application.