unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; MainMenu1: TMainMenu; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; N4: TMenuItem; N5: TMenuItem; procedure N2Click(Sender: TObject); procedure N3Click(Sender: TObject); procedure N5Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; s: string; i,sum,e,c,t: Integer; implementation {$R *.dfm} procedure TForm1.N2Click(Sender: TObject); begin s := Memo1.Text; e := 0; sum := Length(s); for i := 0 to sum do begin if (Ord(s[i]) >= 33) and (Ord(s[i]) <= 126) then Inc(e); end; ShowMessage('字母数: ' + IntToStr(e)); end; procedure TForm1.N3Click(Sender: TObject); begin s := Memo1.Text; c := 0; sum := Length(s); for i:=0 to sum do begin if Ord(s[i]) >= 127 then Inc(c); end; ShowMessage('汉字数: ' + IntToStr(c div 2)); end; procedure TForm1.N5Click(Sender: TObject); begin Close; end; end.