procedure
TWordCountForm.Button1Click(Sender: TObject);
begin
//hide the wordcount form
WordCountForm.Close;
end;
procedure
TWordCountForm.FormShow(Sender: TObject);
Var
Words: Integer; //the number of words
Characters: Integer; //the number of
characters
Space: Boolean; //used to help with the word
count
Add: Boolean; //used to help with the word
count
x: Integer;
//a for loop counter variable
begin
//put the text into the memo to get a line
count
MainForm.Memo.Text :=
Lowercase(MainForm.Text.Text);
//put the numbers into the labels
Words := 0;
Space := True;
Add := False;
For x := 1 to Length(MainForm.Text.Text) do
begin
If (MainForm.Memo.Text[x] = ' ') or
(MainForm.Memo.Text[x] = #13) then
begin
Space := True;
Add := False;
end;
If (MainForm.Memo.Text[x] in ['a'..'z'])
and (Space = True) then
Space := False;
If (Space = False) and (Add = False) then
begin
Add := True;
Words := Words + 1;
end;
end;
Label5.Caption := InttoStr(Words);
Characters := 0;
For x := 1 to Length(MainForm.Text.Text) do
If (MainForm.Text.Text[x] <> #13)
and (MainForm.Text.Text[x] <> #10) and
(MainForm.Text.Text[x] <> ' ')
then Characters := Characters + 1;
Label6.Caption := InttoStr(Characters);
Characters := 0;
For x := 1 to
Length(MainForm.Text.Text) do
If
(MainForm.Text.Text[x] <> #13) and (MainForm.Text.Text[x] <>
#10) then
Characters :=
Characters + 1;
Label7.Caption :=
InttoStr(Characters);
MainForm.Memo.Height := MainForm.Text.Height;
MainForm.Memo.Width
:= MainForm.Text.Width;
Label8.Caption :=
InttoStr(MainForm.Memo.Lines.Count);
end;