unit1.pas

来自「精彩编程百例26~50 其中有 控制任务栏 windows底层任务控制 屏保预览」· PAS 代码 · 共 90 行

PAS
90
字号
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FileCtrl, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    DriveComboBox1: TDriveComboBox;
    DirectoryListBox1: TDirectoryListBox;
    FileListBox1: TFileListBox;
    Label2: TLabel;
    Memo1: TMemo;
    Label3: TLabel;
    Button2: TButton;
    Button3: TButton;
    Label1: TLabel;
    Label4: TLabel;
    txtedit1: TEdit;
    txtedit2: TEdit;
    Button5: TButton;
    procedure Button3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button3Click(Sender: TObject);
begin
    form1.Close;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
   if(filelistbox1.filename='' )then
   messagedlg('请选择一个文本文件',mtInformation,[mbOK],0)  //确定文件是否有效
   else
   Memo1.Lines.LoadFromFile(filelistbox1.filename);   //载入文本信息

End;

procedure TForm1.Button2Click(Sender: TObject);
var
i,e,c:integer;
s:string;
begin
s:=memo1.text;   //赋值给字符串变量
e:=0;c:=0;       //初始化字数统计的整型变量
for i:=1 to length(s) do
  begin
  if (ord(s[i])>=33)and(ord(s[i])<=126) then
    begin
    inc(e);
    txtedit2.text:='英文个数:'+inttostr(e);
    end
  else
  if (ord(s[i])>=127) then
    begin
    inc(c);
    txtedit1.text:='中文个数:'+inttostr(c div 2);
    end;
  end;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
   memo1.Clear;
   txtedit1.Text:='';
   txtedit2.text:='';

end;

end.



⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?