第一问的源码:
unit Main; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls; type TForm1 = class(TForm) btn1: TButton; dlgOpen1: TOpenDialog; lv1: TListView; procedure btn1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses System.RegularExpressions; var ss: TStringStream; procedure TForm1.btn1Click(Sender: TObject); var I: Integer; item: TListItem; temp: string; zimu: string; matchs: TMatchCollection; begin with dlgOpen1 do begin Filter := ‘文本文件(*.txt)|*.txt‘; DefaultExt := ‘txt‘; FileName := ‘‘; Options := [ofHideReadOnly, ofEnableSizing]; if dlgOpen1.Execute then if ofExtensionDifferent in Options then messagedlg(‘这不是文本文件‘, mterror, [mbok], 0) else ss.LoadFromFile(FileName); temp := LowerCase(ss.DataString); end; lv1.Clear; for I := 0 to 26 do begin zimu := AnsiChar(97 + I); item := lv1.Items.Add; item.Caption := zimu; matchs := TRegEx.Matches(temp, zimu); item.SubItems.Add(IntToStr(matchs.Count)); end; item.Free; end; procedure TForm1.FormCreate(Sender: TObject); begin ss := TStringStream.Create; end; procedure TForm1.FormDestroy(Sender: TObject); begin ss.Free; end; end.