Advertisement
Guest User

Untitled

a guest
Jan 14th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.32 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Memo1: TMemo;
  12.     Button1: TButton;
  13.     Button2: TButton;
  14.     OpenDialog1: TOpenDialog;
  15.     Label1: TLabel;
  16.     procedure Button1Click(Sender: TObject);
  17.     procedure Button2Click(Sender: TObject);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.dfm}
  30.  
  31. var
  32.   F:Textfile;
  33.   wordcount:integer;
  34.   S:string;
  35.  
  36. procedure Counter(S:string;wordcount:integer);
  37. var wobe,i:integer;
  38.  begin
  39.    wobe:=0;
  40.    For i:=1 to Length(S) do
  41.     begin
  42.      If ((wobe=0) and (S[i]<>' '))
  43.       then
  44.        begin
  45.         Inc(wordcount);
  46.         wobe:=1;
  47.        end
  48.       else
  49.        begin
  50.         If ((wobe=1) and (S[i]=' ')) then wobe:=0;
  51.        end;
  52.     end;
  53.  end;
  54.  
  55. procedure TForm1.Button1Click(Sender: TObject);
  56. begin
  57. if OpenDialog1.Execute then
  58. Memo1.Lines.LoadFromFile(OpenDialog1.FileName);
  59. end;
  60.  
  61. procedure TForm1.Button2Click(Sender: TObject);
  62. var j:integer;
  63. begin
  64. wordcount:=0;
  65. for j:=1 to Memo1.Lines.Count do
  66.  begin
  67.   S:=Memo1.Lines[j];
  68.   Counter(S,wordcount);
  69.  end;
  70.  Label1.Caption:=IntToStr(wordcount);                                        
  71. end;
  72.  
  73. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement