Author: Tomas Rutkauskas
How to automatically capitalize the first letter of every word when typing in the
field of a TStringGrid
Answer:
Solve 1:
1 2 procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
3 var4 s: string;
5 c: Byte;
6 begin7 with StringGrid1 do8 s := Cells[Col, Row];
9 if Length(s) = 0 then10 begin11 if Key in ['a'..'z'] then12 begin13 c := Ord(Key) - 32;
14 Key := Chr(c);
15 end;
16 exit;
17 end;
18 if s[Length(s)] = ' ' then19 if Key in ['a'..'z'] then20 begin21 c := Ord(Key) - 32;
22 Key := Chr(c);
23 end;
24 end;
Answer 2:
In an onKeyPress event, do this:
25 if length(field.text) = 0 then26 key := upCase(key);