zoukankan      html  css  js  c++  java
  • DelphiTXT文档编辑器

    EXE:http://files.cnblogs.com/xe2011/Text_EditorRelease2013-12-20-185320.rar

    Delphi XE5 PAS:http://files.cnblogs.com/xe2011/Text_Editor_Pascal2013-12-20-185320.rar

     

     字符处理单元

      1 // 字符串处理功能
      2 
      3 unit StringFunctions;
      4 
      5 interface
      6 
      7 uses
      8   Windows, Messages, SysUtils, Variants, Classes, Forms, Dialogs, StdCtrls,
      9   Commctrl;
     10 
     11 type
     12   TStringFunction = class(TObject)
     13   private
     14     function IsUpper(ch: char): boolean;
     15     function IsLower(ch: char): boolean;
     16     function ToUpper(ch: char): char;
     17     function ToLower(ch: char): char;
     18   public
     19     procedure ReplaceSelText(Edit: TCustomEdit; const s: String);
     20     procedure UpperSelText(Edit: TCustomEdit);
     21     procedure LowerSelText(Edit: TCustomEdit);
     22 
     23     function UpperFistLetter(Memo: TMemo): string;
     24 
     25     procedure ClearBlankLine(Memo: TMemo);
     26     procedure ClearBlankSpace(Memo: TMemo);
     27     procedure ClearNum(Memo: TMemo);
     28     procedure ClearLetter(Memo: TMemo);
     29 
     30     procedure InsertNumber(Memo: TMemo);
     31     procedure InsertString(Memo: TMemo; str: string);
     32     procedure InsertComment(Memo: TMemo);
     33     procedure BatchReplaceString(Memo: TMemo);
     34 
     35     procedure JustOneLine(Memo: TMemo);
     36     procedure ReLine(Memo: TMemo; n: Integer);
     37 
     38     procedure TextToHtml(sTextFile, sHtmlFile: string);
     39 
     40     function Proper(const s: string): string;
     41     function CNWordsCount(text: string): Integer;
     42     function ENWordsCount(text: string): Integer;
     43 
     44   end;
     45 
     46 var
     47   StrFunction: TStringFunction;
     48 
     49 implementation
     50 
     51 // 让代码设置Memo后可以让memo在Ctrl+Z撤销有效
     52 procedure TStringFunction.ReplaceSelText(Edit: TCustomEdit; const s: String);
     53 begin
     54   SendMessage(Edit.Handle, EM_REPLACESEL, 1, LPARAM(PChar(s)));
     55   // Edit.Perform(EM_REPLACESEL, 1, LPARAM(PChar(s)));
     56 end;
     57 
     58 // Edit显示行号
     59 // ------------------------------------------------------------------------------
     60 // 去除空行
     61 // Memo1.Text := StringReplace(Memo1.Text, #13#10#13#10, #13#10, [rfReplaceAll]);
     62 {
     63   //无法撤销
     64   //空行的去掉
     65   //本行只有空格的也去掉
     66   //全选
     67   //复制到剪切板上
     68 }
     69 procedure TStringFunction.ClearBlankLine(Memo: TMemo);
     70 var
     71   i: Integer;
     72   list: TStringList;
     73 begin
     74   with Memo do
     75   begin
     76     if Lines.Count > 0 then
     77     begin
     78       list := TStringList.Create;
     79       for i := 0 to Lines.Count - 1 do
     80         if (Trim(Lines[i]) <> '') then
     81           list.Add(Lines[i]);
     82       SelectAll;
     83       ReplaceSelText(Memo, list.text);
     84       list.Free;
     85     end;
     86   end;
     87 end;
     88 
     89 // 去除空格
     90 // 将 空格替换为空
     91 procedure TStringFunction.ClearBlankSpace(Memo: TMemo);
     92 var
     93   s: string;
     94 begin
     95   s := StringReplace(Memo.Lines.text, ' ', '', [rfReplaceAll]);
     96   s := StringReplace(s, ' ', '', [rfReplaceAll]);  //中文的空格
     97 
     98   Memo.SelectAll;
     99   ReplaceSelText(Memo,s);
    100 end;
    101 
    102 // 去除一字符串中的所有的数字
    103 //
    104 procedure TStringFunction.ClearNum(Memo: TMemo);
    105 var
    106   str: string;
    107   i: Integer;
    108 begin
    109   str := '1234567890';
    110   for i := 0 to Length(str) do
    111     Memo.text  := StringReplace(Memo.Lines.text, str[i], '', [rfReplaceAll]);
    112 
    113   { rfReplaceAll
    114     TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase);
    115   }
    116 end;
    117 
    118 // 去除一字符串中的所有的字母
    119 procedure TStringFunction.ClearLetter(Memo: TMemo);
    120 var
    121   str: string;
    122   i: Integer;
    123 begin
    124   str := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    125   for i := 0 to Length(str) do
    126     Memo.text := StringReplace(Memo.Lines.text, str[i], '', [rfReplaceAll]);
    127 end;
    128 
    129 // 批量替换关键字
    130 procedure TStringFunction.BatchReplaceString(Memo: TMemo);
    131 var
    132   i: Integer;
    133 begin
    134   for i := 0 to Length(Memo.Lines.text) do
    135     Memo.text := StringReplace(Memo.Lines.text, Memo.Lines[i], '',
    136       [rfReplaceAll]);
    137   ClearBlankSpace(Memo);
    138 end;
    139 
    140 // ------------------------------------------------------------------------------
    141 // 全角转半角
    142 // 符号有哪些
    143 procedure ConvertQtoB;
    144 begin
    145 
    146 end;
    147 
    148 // 半角转换全角
    149 procedure ConvertBtoQ;
    150 begin
    151 
    152 end;
    153 
    154 { 转换选中的文本大写 }
    155 procedure TStringFunction.UpperSelText(Edit: TCustomEdit);
    156 var
    157   x, y: Integer;
    158 begin
    159   With Edit do
    160   begin
    161     x := SelStart;
    162     y := SelLength;
    163     if SelText <> '' then
    164     begin
    165       ReplaceSelText(Edit, UpperCase(SelText));
    166       SelStart := x;
    167       SelLength := y;
    168     end
    169     else
    170     begin
    171       Edit.SelectAll;
    172       ReplaceSelText(Edit, UpperCase(Edit.text));
    173     end;
    174   end;
    175 end;
    176 
    177 { 转换选中的文本小写 }
    178 procedure TStringFunction.LowerSelText(Edit: TCustomEdit);
    179 var
    180   x, y: Integer;
    181 begin
    182   With Edit do
    183   begin
    184     x := SelStart;
    185     y := SelLength;
    186     if SelText <> '' then
    187     begin
    188       ReplaceSelText(Edit, LowerCase(SelText));
    189       SelStart := x;
    190       SelLength := y;
    191     end
    192     else
    193     begin
    194       Edit.SelectAll;
    195       ReplaceSelText(Edit, LowerCase(Edit.text));
    196     end;
    197   end;
    198 end;
    199 
    200 { 判断字符是否是大写字符 }
    201 function TStringFunction.IsUpper(ch: char): boolean;
    202 begin
    203   Result := ch in ['A' .. 'Z'];
    204 end;
    205 
    206 { 判断字符是否是小写字符 }
    207 function TStringFunction.IsLower(ch: char): boolean;
    208 begin
    209   Result := ch in ['a' .. 'z'];
    210 end;
    211 
    212 { 转换为大写字符 }
    213 function TStringFunction.ToUpper(ch: char): char;
    214 begin
    215   Result := chr(ord(ch) and $DF);
    216 end;
    217 
    218 { 转换为小写字符 }
    219 function TStringFunction.ToLower(ch: char): char;
    220 begin
    221   Result := chr(ord(ch) or $20);
    222 end;
    223 
    224 { Capitalizes First Letter Of Every Word In S 单语首字母大写 }
    225 function TStringFunction.Proper(const s: string): string;
    226 var
    227   i: Integer;
    228   CapitalizeNextLetter: boolean;
    229 begin
    230   Result := LowerCase(s);
    231   CapitalizeNextLetter := True;
    232   for i := 1 to Length(Result) do
    233   begin
    234     if CapitalizeNextLetter and IsLower(Result[i]) then
    235       Result[i] := ToUpper(Result[i]);
    236     CapitalizeNextLetter := Result[i] = ' ';
    237   end;
    238 end;
    239 
    240 { //// Memo选中的首字母大写 }
    241 function TStringFunction.UpperFistLetter(Memo: TMemo): string;
    242 var
    243   lst: TStrings;
    244   i: Integer;
    245   s: string;
    246 begin
    247   lst := TStrings.Create;
    248   lst := Memo.Lines;
    249 
    250   for i := 0 to lst.Count - 1 do
    251   begin
    252     s := s + StrFunction.Proper(lst[i] + #13#10);
    253   end;
    254   Memo.SelectAll;
    255   StrFunction.ReplaceSelText(Memo, s);
    256   // Memo.SelectAll;
    257 end;
    258 
    259 // ------------------------------------------------------------------------------
    260 procedure TStringFunction.InsertNumber(Memo: TMemo);
    261 var
    262   lst: TStrings;
    263   i: Integer;
    264   s: string;
    265 begin
    266   lst := TStrings.Create;
    267   lst := Memo.Lines;
    268 
    269   for i := 0 to lst.Count - 1 do
    270   begin
    271     s := s + Format('%d    %s'#13#10, [i, lst[i]]);;
    272   end;
    273   Memo.SelectAll;
    274   ReplaceSelText(Memo, s);
    275   // Memo.SelectAll;
    276 end;
    277 
    278 procedure TStringFunction.InsertString(Memo: TMemo; str: string);
    279 var
    280   lst: TStrings;
    281   i: Integer;
    282   s: string;
    283 begin
    284   lst := TStrings.Create;
    285   lst := Memo.Lines;
    286 
    287   for i := 0 to lst.Count - 1 do
    288   begin
    289     s := s + Format('%s%s'#13#10, [lst[i], str]);;
    290   end;
    291   Memo.SelectAll;
    292   ReplaceSelText(Memo, s);
    293 end;
    294 
    295 // 注释和取消注释
    296 // 获得选中的文本的起始行和结束行
    297 // 可以通过 MOUSEDOWN MOUSEUP得到
    298 procedure TStringFunction.InsertComment(Memo: TMemo);
    299 var
    300   str: string;
    301   x, y: Integer;
    302 begin
    303   str := Memo.SelText;
    304   x := Memo.SelStart;
    305   y := Memo.SelLength;
    306 
    307   if str = '' then
    308     Exit;
    309   // Memo.SetSelText('//' +str);
    310   Memo.SelText := '//' + str;
    311   Memo.SelStart := x + 2;
    312   Memo.SelLength := y + 2;
    313 
    314 end;
    315 
    316 // ------------------------------------------------------------------------------
    317 // 合并成一行
    318 procedure TStringFunction.JustOneLine(Memo: TMemo);
    319 var
    320   s: string;
    321   i: Integer;
    322 begin
    323   for i := 0 to Memo.Lines.Count - 1 do
    324     s := s + Memo.Lines[i];
    325   Memo.SelectAll;
    326   ReplaceSelText(Memo, s);
    327 end;
    328 
    329 // ------------------------------------------------------------------------------
    330 // 重新分行
    331 {
    332   var
    333   n: Integer;
    334   begin
    335   n := StrToInt(InputBox('重新分行', '每行几个字符', '8'));
    336   ReLine(Memo1, n);
    337   end;
    338 }
    339 procedure TStringFunction.ReLine(Memo: TMemo; n: Integer);
    340 var
    341   s: string;
    342   i, j, k: Integer;
    343   L: TStringList;
    344 begin
    345   L := TStringList.Create;
    346   j := 1;
    347 
    348   for k := 0 to Memo.Lines.Count - 1 do
    349     s := s + Memo.Lines[k];
    350 
    351   if Trim(s) <> '' then
    352   begin
    353     for i := 0 to (Length(s) div n) do // 几行
    354     begin
    355       j := j + n;
    356       L.Add(Copy(s, j - n, n)); // COPY 的第一位不是0是1 // 每行的字符
    357     end;
    358   end;
    359   Memo.SelectAll;
    360   ReplaceSelText(Memo, L.text);
    361   L.Free;
    362 end;
    363 
    364 // ------------------------------------------------------------------------------
    365 // 获得汉字字符个数
    366 function TStringFunction.CNWordsCount(text: string): Integer;
    367 var
    368   i, sum, c: Integer;
    369 begin
    370   Result := 0;
    371 
    372   c := 0;
    373   sum := Length(text);
    374 
    375   if sum = 0 then
    376     Exit;
    377   for i := 0 to sum do
    378   begin
    379     if ord(text[i]) >= 127 then
    380     begin
    381       Inc(c);
    382     end;
    383   end;
    384   Result := c;
    385 end;
    386 
    387 // 获得非汉字字符个数
    388 function TStringFunction.ENWordsCount(text: string): Integer;
    389 var
    390   i, sum, e: Integer;
    391 begin
    392   Result := 0;
    393   e := 0;
    394   sum := Length(text);
    395   if sum = 0 then
    396     Exit;
    397   for i := 0 to sum do
    398   begin
    399     if (ord(text[i]) >= 33) and (ord(text[i]) <= 126) then
    400     begin
    401       Inc(e);
    402     end;
    403   end;
    404   Result := e;
    405 end;
    406 
    407 {
    408   TextToHtml('C:1.txt','c:2.htm');
    409 }
    410 procedure TStringFunction.TextToHtml(sTextFile, sHtmlFile: string);
    411 var
    412   aText: TStringList;
    413   aHtml: TStringList;
    414   i: Integer;
    415 begin
    416   aText := TStringList.Create;
    417   try
    418     aText.LoadFromFile(sTextFile);
    419     aHtml := TStringList.Create;
    420     try
    421       aHtml.Clear;
    422       aHtml.Add('<html>');
    423       aHtml.Add('<body>');
    424       for i := 0 to aText.Count - 1 do
    425         aHtml.Add(aText.Strings[i] + '<br>');
    426       aHtml.Add('</body>');
    427       aHtml.Add('</html>');
    428       aHtml.SaveToFile(sHtmlFile);
    429     finally
    430       aHtml.Free;
    431     end;
    432   finally
    433     aText.Free;
    434   end;
    435 end;
    436 
    437 Initialization
    438 
    439 StrFunction := TStringFunction.Create;
    440 
    441 Finalization
    442 
    443 StrFunction.Free;
    444 
    445 end.
    View Code

     主窗体单元

      1 unit TextEditor;
      2 
      3 interface
      4 
      5 uses
      6   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
      7   System.Classes, Vcl.Graphics,
      8   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.StdCtrls, Vcl.ComCtrls,
      9   Vcl.StdActns, Vcl.ActnList, Vcl.ExtActns, System.Actions, Vcl.ExtCtrls,
     10   Vcl.ExtDlgs, INIFILES;
     11 
     12 function GetUserDefaultUILanguage(): Integer; external 'Kernel32.DLL';
     13 
     14 type
     15   TTextEditorForm = class(TForm)
     16     Memo1: TMemo;
     17     StatusBar1: TStatusBar;
     18     MainMenu1: TMainMenu;
     19     mni_File: TMenuItem;
     20     FileNew: TMenuItem;
     21     FileOpen: TMenuItem;
     22     FileSave: TMenuItem;
     23     FileSaveAs: TMenuItem;
     24     mni_PageSetup: TMenuItem;
     25     mni_Print: TMenuItem;
     26     mni_Exit: TMenuItem;
     27     mni_Edit: TMenuItem;
     28     mni_Undo: TMenuItem;
     29     mni_Cut: TMenuItem;
     30     mni_Copy: TMenuItem;
     31     mni_Paste: TMenuItem;
     32     mni_Delete: TMenuItem;
     33     mni_Find: TMenuItem;
     34     mni_FindNext: TMenuItem;
     35     mni_Replace: TMenuItem;
     36     mni_GoTo: TMenuItem;
     37     mni_SelectAll: TMenuItem;
     38     mni_DateTime: TMenuItem;
     39     mni_Format: TMenuItem;
     40     mni_Font: TMenuItem;
     41     mni_WordWrap: TMenuItem;
     42     mni_View: TMenuItem;
     43     mni_StatusBar: TMenuItem;
     44     mni_Help: TMenuItem;
     45     mni_ViewHelp: TMenuItem;
     46     mni_About: TMenuItem;
     47     mni_SetTopMoset: TMenuItem;
     48     FindDialog1: TFindDialog;
     49     ReplaceDialog1: TReplaceDialog;
     50     Tools: TMenuItem;
     51     Options1: TMenuItem;
     52     N2: TMenuItem;
     53     Convert1: TMenuItem;
     54     Clear1: TMenuItem;
     55     Bat1: TMenuItem;
     56     Rnd1: TMenuItem;
     57     Total1: TMenuItem;
     58     upperCase: TMenuItem;
     59     Lowercase: TMenuItem;
     60     N3: TMenuItem;
     61     UpperFirstLatter: TMenuItem;
     62     InsertNumber: TMenuItem;
     63     Comment: TMenuItem;
     64     NoBank: TMenuItem;
     65     BatNoKeyWord: TMenuItem;
     66     N5: TMenuItem;
     67     NoSpace: TMenuItem;
     68     NoNumber: TMenuItem;
     69     NoLetter: TMenuItem;
     70     CombineOne: TMenuItem;
     71     ReLine: TMenuItem;
     72     N7: TMenuItem;
     73     BatCreateFile: TMenuItem;
     74     BatCreateFolder: TMenuItem;
     75     BatCreateRename: TMenuItem;
     76     N4: TMenuItem;
     77     N1: TMenuItem;
     78     HTMLTXT1: TMenuItem;
     79     XTHTML1: TMenuItem;
     80     RecentFiles: TMenuItem;
     81     ClearFiles: TMenuItem;
     82     N6: TMenuItem;
     83     ComplexText1: TMenuItem;
     84     SimpleText1: TMenuItem;
     85     mni_InsertRightStr: TMenuItem;
     86     ASCIIHEX1: TMenuItem;
     87     HEXASCII1: TMenuItem;
     88     N8: TMenuItem;
     89     procedure FormResize(Sender: TObject);
     90     procedure mni_WordWrapClick(Sender: TObject);
     91     procedure mni_AboutClick(Sender: TObject);
     92     procedure mni_FontClick(Sender: TObject);
     93     procedure mni_DateTimeClick(Sender: TObject);
     94     procedure mni_GoToClick(Sender: TObject);
     95     procedure mni_StatusBarClick(Sender: TObject);
     96     procedure FormCreate(Sender: TObject);
     97     procedure SaveConfig(Sender: TObject);
     98     procedure LoadConfig(Sender: TObject);
     99     procedure FormClose(Sender: TObject; var Action: TCloseAction);
    100     procedure mni_PrintClick(Sender: TObject);
    101     procedure mni_SetTopMosetClick(Sender: TObject);
    102     procedure Memo1MouseUp(Sender: TObject; Button: TMouseButton;
    103       Shift: TShiftState; X, Y: Integer);
    104     procedure act_SetCaretPosExecute(Sender: TObject);
    105     procedure Memo1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    106     procedure FindDialog1Find(Sender: TObject);
    107     procedure mni_DeleteClick(Sender: TObject);
    108     procedure mni_PasteClick(Sender: TObject);
    109     procedure mni_CopyClick(Sender: TObject);
    110     procedure mni_CutClick(Sender: TObject);
    111     procedure ReplaceDialog1Replace(Sender: TObject);
    112     procedure ReplaceDialog1Find(Sender: TObject);
    113     procedure mni_FindNextClick(Sender: TObject);
    114     procedure mni_FindClick(Sender: TObject);
    115     procedure mni_ReplaceClick(Sender: TObject);
    116     procedure mni_EditClick(Sender: TObject);
    117     procedure mni_UndoClick(Sender: TObject);
    118     procedure mni_PageSetupClick(Sender: TObject);
    119     procedure mni_ExitClick(Sender: TObject);
    120     procedure Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    121     procedure mni_SelectAllClick(Sender: TObject);
    122     procedure Memo1KeyPress(Sender: TObject; var Key: Char);
    123     procedure FileNewClick(Sender: TObject);
    124     procedure FileOpenClick(Sender: TObject);
    125     procedure FileSaveClick(Sender: TObject);
    126     procedure FileSaveAsClick(Sender: TObject);
    127     procedure Total1Click(Sender: TObject);
    128     procedure upperCaseClick(Sender: TObject);
    129     procedure LowercaseClick(Sender: TObject);
    130     procedure UpperFirstLatterClick(Sender: TObject);
    131     procedure NoSpaceClick(Sender: TObject);
    132     procedure NoBankClick(Sender: TObject);
    133     procedure CombineOneClick(Sender: TObject);
    134     procedure ReLineClick(Sender: TObject);
    135     procedure HTMLTXT1Click(Sender: TObject);
    136     procedure InsertNumberClick(Sender: TObject);
    137     procedure mni_InsertRightStrClick(Sender: TObject);
    138     procedure NoNumberClick(Sender: TObject);
    139     procedure NoLetterClick(Sender: TObject);
    140     procedure mni_ViewHelpClick(Sender: TObject);
    141   private
    142     { Private declarations }
    143     FFileName: string;
    144     procedure CheckFileSave;
    145     procedure SetFileName(const FileName: String);
    146     procedure PerformFileOpen(const AFileName: string);
    147     procedure WMDropFiles(var Msg: TWMDropFiles); message WM_DROPFILES;
    148 
    149     // ------------------------------------------------------------------------------
    150     // procedure WMDROPFILES(var MSg: TMessage); message WM_DROPFILES;
    151     procedure GoToMemoLineDialog(Memo: TMemo);
    152     procedure SetUiCHS();
    153     procedure SetUiEN();
    154     procedure MemoPrinter(Memo: TMemo; TitleStr: string = '无标题');
    155 
    156 
    157     // ------------------------------------------------------------------------------
    158 
    159   public
    160     { Public declarations }
    161   end;
    162 
    163 var
    164   TextEditorForm: TTextEditorForm;
    165   FindStr: string;
    166   bStatueBar: Boolean = False;
    167   AppINI: string;
    168   // ------------------------------------------------------------------------------
    169 
    170 implementation
    171 
    172 uses
    173   ShellApi, Registry, Printers, Clipbrd, StrUtils,
    174   Search, StringFunctions, Encrypt, Config, SimpleConvert;
    175 {$R *.dfm}
    176 
    177 resourcestring
    178   sSaveChanges = '是否将未更改保存到 %s?';
    179   sOverWrite = '%s 已存在。' + #13#10 + '要替换它吗?';
    180   sTitle = '记事本';
    181   sUntitled = '未命名';
    182   sColRowInfo = '行: %3d   列: %3d';
    183   sLine = ''; //
    184   scol = '';
    185   sGoToTitle = '转到指定行'; // 轮到行的 输入对话框的标题
    186   sGoToTips = '行号(&L):'; //
    187   sMsgBoxTitle = '行数超过了总行数';
    188   sFileDlgFilter = '文本文档(*.txt)|*.txt|所有文件(*.*)|*.*'; // 打开和保存的文本是一样的
    189 
    190 procedure TextToHtml(Memo: TMemo);
    191 var
    192   lst: TStringList;
    193   i: Integer;
    194 begin
    195   try
    196     lst := TStringList.Create;
    197     with lst do
    198     begin
    199       Clear;
    200       Add('<html>');
    201       Add('<body>');
    202       for i := 0 to Memo.Lines.Count - 1 do
    203         Add(Memo.Lines[i] + '<br>');
    204       Add('</body>');
    205       Add('</html>');
    206       Memo.text := text;
    207       ShowMessage(text);
    208     end;
    209   finally
    210     lst.Free;
    211   end;
    212 end;
    213 
    214 procedure TTextEditorForm.CheckFileSave;
    215 var
    216   SaveRespond: Integer;
    217 begin
    218   if not Memo1.Modified then
    219     Exit;
    220   SaveRespond := MessageBox(Handle, PWideChar(Format(sSaveChanges, [FFileName])
    221     ), PWideChar(sTitle), MB_YESNOCANCEL + MB_ICONINFORMATION);
    222   case SaveRespond of
    223     idYes:
    224       FileSave.click;
    225     idNo:
    226       ; { Nothing }
    227     idCancel:
    228       Abort;
    229   end;
    230 end;
    231 
    232 procedure TTextEditorForm.CombineOneClick(Sender: TObject);
    233 begin
    234   strfunction.JustOneLine(Memo1);
    235 end;
    236 
    237 procedure TTextEditorForm.SetFileName(const FileName: String);
    238 begin
    239   FFileName := FileName;
    240   Caption := Format('%s - %s', [ExtractFileName(FileName), sTitle]);
    241 end;
    242 
    243 procedure TTextEditorForm.PerformFileOpen(const AFileName: string);
    244 begin
    245   Memo1.Lines.LoadFromFile(AFileName);
    246   SetFileName(AFileName);
    247   Memo1.SetFocus;
    248   Memo1.Modified := False;
    249 end;
    250 
    251 procedure TTextEditorForm.WMDropFiles(var Msg: TWMDropFiles);
    252 var
    253   CFileName: array [0 .. MAX_PATH] of Char;
    254 begin
    255   try
    256     if DragQueryFile(Msg.Drop, 0, CFileName, MAX_PATH) > 0 then
    257     begin
    258       CheckFileSave;
    259       PerformFileOpen(CFileName);
    260       Msg.Result := 0;
    261     end;
    262   finally
    263     DragFinish(Msg.Drop);
    264   end;
    265 end;
    266 
    267 { ReplaceDialog Find }
    268 procedure TTextEditorForm.ReLineClick(Sender: TObject);
    269 var
    270   n: Integer;
    271 begin
    272   n := StrToInt(InputBox('重新分行', '每行几个字符', '8'));
    273   strfunction.ReLine(Memo1, n);
    274 end;
    275 
    276 procedure TTextEditorForm.ReplaceDialog1Find(Sender: TObject);
    277 begin
    278   with Sender as TReplaceDialog do
    279     if not SearchMemo(Memo1, FindText, Options) then
    280       MessageBox(Handle, PWideChar(Concat('找不到"', FindText, '"')), '记事本',
    281         MB_ICONINFORMATION);
    282 end;
    283 
    284 { ReplaceDialog Replace }
    285 procedure TTextEditorForm.ReplaceDialog1Replace(Sender: TObject);
    286 var
    287   Found: Boolean;
    288 begin
    289   with ReplaceDialog1 do
    290   begin
    291     { Replace }
    292     if (frReplace in Options) and (Memo1.SelText = FindText) then
    293       Memo1.SelText := ReplaceText;
    294     Found := SearchMemo(Memo1, FindText, Options);
    295 
    296     { Replace All }
    297     if (frReplaceAll in Options) then
    298     begin
    299       Memo1.SelStart := 0;
    300       while Found do
    301       begin
    302         if (Memo1.SelText = FindText) then
    303           Memo1.SelText := ReplaceText;
    304         Found := SearchMemo(Memo1, FindText, Options);
    305       end;
    306       if not Found then
    307         SendMessage(Memo1.Handle, WM_VSCROLL, SB_TOP, 0);
    308     end;
    309 
    310     if (not Found) and (frReplace in Options) then
    311       MessageBox(Handle, PWideChar(Concat('找不到"', FindText, '"')), '记事本',
    312         MB_ICONINFORMATION);
    313   end;
    314 
    315 end;
    316 
    317 procedure TTextEditorForm.FileNewClick(Sender: TObject);
    318 begin
    319   CheckFileSave;
    320   SetFileName(sUntitled);
    321 
    322   Memo1.Lines.Clear;
    323   Memo1.Modified := False;
    324 end;
    325 
    326 procedure TTextEditorForm.FileOpenClick(Sender: TObject);
    327 begin
    328   CheckFileSave;
    329 
    330   with TOpenDialog.Create(nil) do
    331   begin
    332     Filter := sFileDlgFilter;
    333     FileName := '*.txt';
    334     if Execute then
    335     begin
    336       PerformFileOpen(FileName);
    337       Memo1.ReadOnly := ofReadOnly in Options;
    338     end;
    339   end;
    340 end;
    341 
    342 procedure TTextEditorForm.FileSaveClick(Sender: TObject);
    343 begin
    344   if FFileName = sUntitled then
    345     FileSaveAs.click
    346   else
    347   begin
    348     Memo1.Lines.SaveToFile(FFileName);
    349     Memo1.Modified := False;
    350   end;
    351 end;
    352 
    353 procedure TTextEditorForm.FileSaveAsClick(Sender: TObject);
    354 begin
    355   with TSaveDialog.Create(nil) do
    356   begin
    357     Filter := sFileDlgFilter;
    358     FileName := '*.txt';
    359     if Execute then
    360     begin
    361       if FileExists(FileName) then
    362         if MessageBox(Handle, PWideChar(Format(sOverWrite, [FFileName])),
    363           PWideChar(sTitle), MB_YESNOCANCEL + MB_ICONINFORMATION) <> idYes then
    364           Exit;
    365       Memo1.Lines.SaveToFile(FileName);
    366       SetFileName(FileName);
    367       Memo1.Modified := False;
    368     end;
    369   end;
    370 end;
    371 
    372 procedure TTextEditorForm.FindDialog1Find(Sender: TObject);
    373 begin
    374   with Sender as TFindDialog do
    375   begin
    376     FindStr := FindText;
    377     if not SearchMemo(Memo1, FindText, Options) then
    378       MessageBox(Handle, PWideChar(Concat('找不到"', FindText, '"')), '记事本',
    379         MB_ICONINFORMATION);
    380   end;
    381 end;
    382 
    383 procedure TTextEditorForm.FormClose(Sender: TObject; var Action: TCloseAction);
    384 begin
    385   SaveConfig(Sender);
    386   Action := caFree;
    387 
    388   CheckFileSave;
    389 end;
    390 
    391 procedure TTextEditorForm.FormCreate(Sender: TObject);
    392 begin
    393 
    394   AppINI := ExtractFilePath(Application.ExeName) + 'Text Editor.ini';
    395 
    396   SetFileName(sUntitled);
    397   DragAcceptFiles(Handle, True);
    398   // FindDialog1.Options := [frDown, frHideWholeWord];
    399   // ReplaceDialog1.Options := [frDown, frHideWholeWord];
    400   with Memo1 do
    401   begin
    402     HideSelection := False;
    403     ScrollBars := ssVertical;
    404     Align := alClient;
    405   end;
    406 
    407   act_SetCaretPosExecute(Sender);
    408 
    409   if GetUserDefaultUILanguage() = $0804 then
    410     SetUiCHS // Caption:='简体中文';
    411   else
    412     SetUiEN; // Caption:='英文';
    413 
    414   // Caption := Form1Title;
    415   LoadConfig(Sender);
    416   bStatueBar := mni_StatusBar.Checked;
    417 
    418   if mni_WordWrap.Checked then
    419   begin
    420     mni_WordWrap.click;
    421     mni_WordWrap.Checked := True;
    422     // 可以自动换行
    423     Memo1.ScrollBars := ssVertical;
    424     Memo1.WordWrap := True;
    425     mni_GoTo.Enabled := False;
    426     mni_StatusBar.Checked := False;
    427     mni_StatusBar.Enabled := False;
    428     StatusBar1.Visible := False;
    429   end
    430   else
    431   begin
    432     // 不能换行
    433     Memo1.ScrollBars := ssBoth;
    434     Memo1.WordWrap := False;
    435     mni_GoTo.Enabled := True;
    436     mni_StatusBar.Enabled := True;
    437     StatusBar1.Visible := bStatueBar;
    438   end;
    439 
    440   bStatueBar := mni_StatusBar.Checked;
    441   mni_StatusBar.Checked := bStatueBar;
    442   StatusBar1.Panels[0].Width := (75 * StatusBar1.Width) div 100;
    443 end;
    444 
    445 procedure TTextEditorForm.FormResize(Sender: TObject);
    446 begin
    447   StatusBar1.Panels[0].Width := (75 * StatusBar1.Width) div 100;
    448   // SaveConfig(Sender);
    449 end;
    450 
    451 procedure TTextEditorForm.GoToMemoLineDialog(Memo: TMemo);
    452 var
    453   LineIndex1, LineLength1, selStart1, Line, i: Integer;
    454 begin
    455   selStart1 := 0;
    456   Line := StrToInt(InputBox(sGoToTitle, sGoToTips,
    457     IntToStr(Memo.CaretPos.Y + 1))) - 1;
    458 
    459   if (Line > 0) and (Line <= Memo.Lines.Count) then
    460     for i := 0 to Line - 1 do
    461     begin
    462       LineIndex1 := SendMessage(Memo.Handle, EM_LINEINDEX, i, 0);
    463       LineLength1 := SendMessage(Memo.Handle, EM_LINELENGTH, LineIndex1, 0) + 2;
    464       selStart1 := selStart1 + LineLength1;
    465     end
    466   else if Line = 0 then
    467     Memo.SelStart := selStart1
    468   else
    469     MessageBox(Handle, PWideChar('行数超出了总行数'), PWideChar('记事本 - 跳行'), 0);
    470   Memo.SelStart := selStart1;
    471 end;
    472 
    473 procedure TTextEditorForm.HTMLTXT1Click(Sender: TObject);
    474 begin
    475   TextToHtml(Memo1);
    476 end;
    477 
    478 procedure TTextEditorForm.InsertNumberClick(Sender: TObject);
    479 begin
    480   strfunction.InsertNumber(Memo1);
    481 end;
    482 
    483 procedure TTextEditorForm.LowercaseClick(Sender: TObject);
    484 begin
    485   strfunction.LowerSelText(Memo1);
    486 end;
    487 
    488 procedure TTextEditorForm.Memo1KeyDown(Sender: TObject; var Key: Word;
    489   Shift: TShiftState);
    490 begin
    491   { 你猜在编辑菜单中为何不使用系统的HotKey而在这里用手动来实现快捷键
    492     去除声音
    493   }
    494   if (Shift = [ssCtrl]) and (Key = $46) then // 按下<Ctrl+F>
    495     mni_Find.click;
    496 
    497   if (Key = vk_F3) and mni_FindNext.Enabled then // F3
    498     mni_FindNext.click;
    499 
    500   if (Shift = [ssCtrl]) and (Key = $48) then // Ctrl+H
    501     mni_Replace.click;
    502 
    503   if (Shift = [ssCtrl]) and (Key = $47) and (not Memo1.WordWrap) then // Ctrl+G
    504     mni_GoTo.click;
    505 
    506   if (Shift = [ssCtrl]) and (Key = $41) then // Ctrl+A
    507     mni_SelectAll.click;
    508 
    509   if (Key = vk_F5) then // F5
    510     mni_DateTime.click;
    511 end;
    512 
    513 procedure TTextEditorForm.Memo1KeyPress(Sender: TObject; var Key: Char);
    514 begin
    515   // F,H,G,A
    516   if (Key = #6) or (Key = #1) { or (Key = #8) } or (Key = #7) then
    517     Key := #0;
    518 end;
    519 
    520 procedure TTextEditorForm.Memo1KeyUp(Sender: TObject; var Key: Word;
    521   Shift: TShiftState);
    522 begin
    523   act_SetCaretPosExecute(Sender);
    524 end;
    525 
    526 procedure TTextEditorForm.Memo1MouseUp(Sender: TObject; Button: TMouseButton;
    527   Shift: TShiftState; X, Y: Integer);
    528 begin
    529 
    530   act_SetCaretPosExecute(Sender);
    531 end;
    532 
    533 // ------------------------------------------------------------------------------
    534 { Edit Menu Item Enable }
    535 procedure TTextEditorForm.mni_EditClick(Sender: TObject);
    536 begin
    537   mni_Find.Enabled := (Memo1.text <> '');
    538   mni_FindNext.Enabled := (Memo1.text <> '') and (FindStr <> '');
    539   mni_Replace.Enabled := (Memo1.text <> '');
    540 
    541   mni_GoTo.Enabled := not Memo1.WordWrap;
    542   mni_Undo.Enabled := Memo1.Modified;
    543   mni_Cut.Enabled := (Memo1.SelLength > 0);
    544   mni_Copy.Enabled := (Memo1.SelLength > 0);
    545   mni_Paste.Enabled := Clipboard.HasFormat(CF_TEXT);
    546   mni_Delete.Enabled := (Memo1.text <> '');
    547   // mni_SelectAll.Enabled:= ( Memo1.SelLength <> Length(Memo1.Text) );
    548 end;
    549 
    550 procedure TTextEditorForm.mni_AboutClick(Sender: TObject);
    551 begin
    552   ShellAbout(Handle, PWideChar('记事本'),
    553     'Roman E-Main:450640526@qq.com 2013年6月15日17:46:18',
    554     Application.Icon.Handle);
    555 end;
    556 
    557 procedure TTextEditorForm.mni_CopyClick(Sender: TObject);
    558 begin
    559   Memo1.CopyToClipboard
    560 end;
    561 
    562 procedure TTextEditorForm.mni_CutClick(Sender: TObject);
    563 begin
    564   Memo1.CutToClipboard;
    565 end;
    566 
    567 procedure TTextEditorForm.mni_DeleteClick(Sender: TObject);
    568 begin
    569   // 没选中也能删除的
    570   // 快捷键del去掉就可以正常使用了
    571   Memo1.ClearSelection;
    572 end;
    573 
    574 procedure TTextEditorForm.mni_SelectAllClick(Sender: TObject);
    575 begin
    576   Memo1.SelectAll;
    577 end;
    578 
    579 procedure TTextEditorForm.mni_DateTimeClick(Sender: TObject);
    580 begin
    581   Memo1.SetSelText((FormatDateTime('hh:mm yyyy/m/dd', now))); // 插入时间/日期
    582 end;
    583 
    584 procedure TTextEditorForm.mni_ExitClick(Sender: TObject);
    585 begin
    586   Close;
    587 end;
    588 
    589 // 调用查找对话框
    590 procedure TTextEditorForm.mni_FindClick(Sender: TObject);
    591 begin
    592   with FindDialog1 do
    593   begin
    594     Left := Self.Left + 100;
    595     Top := Self.Top + 150;
    596     FindText := Memo1.SelText;
    597     Execute;
    598   end;
    599 end;
    600 
    601 { ReplaceDialog1.Execute }
    602 procedure TTextEditorForm.mni_ReplaceClick(Sender: TObject);
    603 begin
    604   with ReplaceDialog1 do
    605   begin
    606     Left := Self.Left + 100;
    607     Top := Self.Top + 150;
    608     FindText := Memo1.SelText;
    609     Execute;
    610   end;
    611 end;
    612 
    613 { Find Next }
    614 procedure TTextEditorForm.mni_FindNextClick(Sender: TObject);
    615 begin
    616   if not SearchMemo(Memo1, FindStr, FindDialog1.Options) then
    617     MessageBox(Handle, PWideChar(Concat('找不到"', FindStr, '"')), '记事本',
    618       MB_ICONINFORMATION);
    619 end;
    620 
    621 procedure TTextEditorForm.mni_FontClick(Sender: TObject);
    622 begin
    623   with TFontDialog.Create(nil) do
    624   begin
    625     Font := Memo1.Font;
    626     Options := [fdApplyButton];
    627     if Execute() then
    628       Memo1.Font := Font;
    629   end;
    630 end;
    631 
    632 procedure TTextEditorForm.mni_GoToClick(Sender: TObject);
    633 begin
    634   GoToMemoLineDialog(Memo1);
    635 end;
    636 
    637 procedure TTextEditorForm.mni_InsertRightStrClick(Sender: TObject);
    638 var
    639   str: string;
    640 begin
    641   str := InputBox('提示', '放在每行的最右边的字符串', ' - Hello Roman');
    642   strfunction.InsertString(Memo1, str);
    643 end;
    644 
    645 procedure TTextEditorForm.mni_PageSetupClick(Sender: TObject);
    646 begin
    647   With TPageSetupDialog.Create(nil) do
    648     Execute;
    649 end;
    650 
    651 procedure TTextEditorForm.mni_PasteClick(Sender: TObject);
    652 begin
    653   Memo1.PasteFromClipboard;
    654 end;
    655 
    656 procedure TTextEditorForm.mni_PrintClick(Sender: TObject);
    657 begin
    658   MemoPrinter(Memo1); // 标题修改为文件名
    659 end;
    660 
    661 procedure TTextEditorForm.mni_StatusBarClick(Sender: TObject);
    662 begin
    663   if mni_StatusBar.Checked then
    664   begin
    665     bStatueBar := True;
    666     StatusBar1.Visible := True;
    667   end
    668 
    669   else
    670   begin
    671     StatusBar1.Visible := False;
    672     bStatueBar := False;
    673   end;
    674 end;
    675 
    676 procedure TTextEditorForm.mni_UndoClick(Sender: TObject);
    677 begin
    678   Memo1.Undo;
    679 end;
    680 
    681 procedure TTextEditorForm.mni_ViewHelpClick(Sender: TObject);
    682 begin
    683   ShellExecute(Handle, 'open', 'http://www.cnblogs.com/xe2011/p/3483809.html',
    684     0, 0, SW_SHOWNORMAL);
    685 end;
    686 
    687 procedure TTextEditorForm.mni_WordWrapClick(Sender: TObject);
    688 begin
    689   if mni_WordWrap.Checked then
    690   begin
    691     Memo1.ScrollBars := ssVertical; // 自动换行
    692     Memo1.WordWrap := True;
    693 
    694     // 转到 和  状态栏不可用  和状态栏菜单不可用 check为false
    695     mni_GoTo.Enabled := False;
    696 
    697     // ----------------------------------------
    698     mni_StatusBar.Enabled := False;
    699     mni_StatusBar.Checked := False;
    700     StatusBar1.Visible := False;
    701   end
    702   else
    703   begin
    704     Memo1.ScrollBars := ssBoth; // 取消自动换行
    705     Memo1.WordWrap := False;
    706 
    707     mni_GoTo.Enabled := True;
    708 
    709     // ----------------------------------------
    710     mni_StatusBar.Enabled := True;
    711     mni_StatusBar.Checked := bStatueBar;
    712     StatusBar1.Visible := bStatueBar;
    713   end;
    714   // if bStatueBar=True then Caption:='True';
    715   // if bStatueBar=False then Caption:='False';
    716 
    717 end;
    718 
    719 procedure TTextEditorForm.NoBankClick(Sender: TObject);
    720 begin
    721   strfunction.ClearBlankLine(Memo1);
    722 end;
    723 
    724 procedure TTextEditorForm.NoLetterClick(Sender: TObject);
    725 begin
    726   strfunction.ClearLetter(Memo1);
    727 end;
    728 
    729 procedure TTextEditorForm.NoNumberClick(Sender: TObject);
    730 begin
    731   strfunction.ClearNum(Memo1);
    732 end;
    733 
    734 procedure TTextEditorForm.NoSpaceClick(Sender: TObject);
    735 begin
    736   strfunction.ClearBlankSpace(Memo1);
    737 end;
    738 
    739 procedure TTextEditorForm.mni_SetTopMosetClick(Sender: TObject);
    740 begin
    741   if mni_SetTopMoset.Checked then
    742     FormStyle := fsStayOnTop
    743   else
    744     FormStyle := fsNormal;
    745 end;
    746 
    747 procedure TTextEditorForm.SetUiCHS();
    748 begin
    749   // SetUICH
    750   // ------------------------------------------
    751   mni_File.Caption := '文件(&F)';
    752   FileNew.Caption := '新建(&N)';
    753   FileOpen.Caption := '打开(&O)...';
    754   FileSave.Caption := '保存(&S)';
    755   FileSaveAs.Caption := '另存为(&A)...';
    756   mni_PageSetup.Caption := '页面设置(&U)...';
    757   mni_Print.Caption := '打印(&P)...';
    758   mni_Exit.Caption := '退出(&X)';
    759   // ------------------------------------------
    760   mni_Edit.Caption := '编辑(&E)';
    761   mni_Undo.Caption := '撤消(&U)           Ctrl+Z';
    762   mni_Cut.Caption := '剪切(&T)           Ctrl+X';
    763   mni_Copy.Caption := '复制(&C)           Ctrl+C';
    764   mni_Paste.Caption := '粘贴(&P)           Ctrl+V';
    765   mni_Delete.Caption := '删除(&L))          Del';
    766   mni_Find.Caption := '查找(F)...        Ctrl+F';
    767   mni_FindNext.Caption := '查找下一个(&N)     F3';
    768   mni_Replace.Caption := '替换(&R)...        Ctrl+H';
    769   mni_GoTo.Caption := '转到(&G)...        Ctrl+G';
    770   mni_SelectAll.Caption := '全选(&A)           Ctrl+A';
    771   mni_DateTime.Caption := '时间/日期(&D)      F5';
    772   // ------------------------------------------
    773   mni_Format.Caption := '格式(&O)';
    774   mni_WordWrap.Caption := '自动换行(&W)';
    775   mni_Font.Caption := '字体(&F)...';
    776   // ------------------------------------------
    777   mni_View.Caption := '查看(&V)';
    778   mni_StatusBar.Caption := '状态栏(&S)';
    779   mni_SetTopMoset.Caption := '置顶(&T)';
    780   // ------------------------------------------
    781   mni_Help.Caption := '帮助(&H)';
    782   mni_ViewHelp.Caption := '查看帮助(&H)';
    783   mni_About.Caption := '关于记事本(&A)';
    784 
    785   // // ------------------------------------------
    786   // Form1Title := '无标题 - 记事本';
    787   // Line := ''; //
    788   // col := '';
    789   // sGoToTitle := '转到指定行'; // 轮到行的 输入对话框的标题
    790   // sGoToTips := '行号(&L):'; //
    791   // MsgBoxTitle := '行数超过了总行数';
    792   // MsgBoxHint := '记事本 - 跳行';
    793   // shellAboutText := '关于 - 记事本';
    794   // FileDialogFilter := '文本文档(*.txt)|*.txt|所有文件(*.*)|*.*';
    795 
    796 end;
    797 
    798 procedure TTextEditorForm.SetUiEN();
    799 begin
    800   // SetUIENGLISH
    801   // ------------------------------------------
    802   mni_File.Caption := '&File';
    803   FileNew.Caption := '&New';
    804   FileOpen.Caption := '&Open...';
    805   FileSave.Caption := '&Save';
    806   FileSaveAs.Caption := 'Save &As...';
    807   mni_PageSetup.Caption := 'Page Set&up...';
    808   mni_Print.Caption := '&Print...';
    809   mni_Exit.Caption := 'E&xit';
    810   // ------------------------------------------
    811   mni_Edit.Caption := '&Edit';
    812   mni_Undo.Caption := '&Undo           Ctrl+Z';
    813   mni_Cut.Caption := 'Cu&t           Ctrl+X';
    814   mni_Copy.Caption := '&Copy           Ctrl+C';
    815   mni_Paste.Caption := '&Paste)           Ctrl+V';
    816   mni_Delete.Caption := '&Delete          Del';
    817   mni_Find.Caption := '&Find...        Ctrl+F';
    818   mni_FindNext.Caption := 'Find &Next     F3';
    819   mni_Replace.Caption := '&Replace...        Ctrl+H';
    820   mni_GoTo.Caption := '&Go To...        Ctrl+G';
    821   mni_SelectAll.Caption := 'Select &All           Ctrl+A';
    822   mni_DateTime.Caption := 'Time/&Date      F5';
    823   // ------------------------------------------
    824   mni_Format.Caption := 'F&ormat';
    825   mni_WordWrap.Caption := '&Word Wrap';
    826   mni_Font.Caption := '&Font...';
    827   // ------------------------------------------
    828   mni_View.Caption := '&View';
    829   mni_StatusBar.Caption := '&StatueBar';
    830   mni_SetTopMoset.Caption := '&TopMost';
    831   // ------------------------------------------
    832   mni_Help.Caption := '&Help';
    833   mni_ViewHelp.Caption := 'View H&elp';
    834   mni_About.Caption := '&About Notepad';
    835 
    836   // // ------------------------------------------
    837   // Form1Title := 'Untitled - Notepad';
    838   // Line := 'Ln'; //
    839   // col := 'Col';
    840   // sGoToTitle := 'Go To Line'; // 轮到行的 输入对话框的标题
    841   // sGoToTips := '&Line Number:'; //
    842   // MsgBoxTitle := 'The line number is beyond the total number of lines';
    843   // MsgBoxHint := 'Notepad - Goto Line';
    844   // shellAboutText := ' - Notepad';
    845   // FileDialogFilter := 'Text File(*.txt)|*.txt|All File(*.*)|*.*';
    846 end;
    847 
    848 procedure TTextEditorForm.Total1Click(Sender: TObject);
    849 var
    850   Line: Integer;
    851   Count: Integer;
    852   en, cn: Integer;
    853   s: string;
    854 begin
    855   with Memo1 do
    856   begin
    857     Line := Memo1.Lines.Count;
    858     Count := Length(Memo1.Lines.text);
    859     en := strfunction.ENWordsCount(text);
    860     cn := strfunction.CNWordsCount(text);
    861   end;
    862   s := Format
    863     ('行                          %d '#13'字符(全部 包括空格)  %d '#13'字符(非汉字 无空格)  %d '#13'汉字(汉字字符)         %d',
    864     [Line, Count, en, cn]);
    865   Application.MessageBox(PWideChar(s), '统计 - 记事本', MB_ICONINFORMATION);
    866 end;
    867 
    868 procedure TTextEditorForm.upperCaseClick(Sender: TObject);
    869 begin
    870   strfunction.UpperSelText(Memo1);
    871 end;
    872 
    873 procedure TTextEditorForm.UpperFirstLatterClick(Sender: TObject);
    874 begin
    875   strfunction.UpperFistLetter(Memo1);
    876 end;
    877 
    878 // Printers
    879 procedure TTextEditorForm.MemoPrinter(Memo: TMemo; TitleStr: string = '无标题');
    880 var
    881   Left: Integer;
    882   Top: Integer;
    883   i, j, X, Y: Integer; // PageHeight,
    884   PagesStr: String;
    885   posX, posY, Posx1, posY1: Integer;
    886   PrintDialog1: TPrintDialog;
    887 begin
    888   Left := 500;
    889   Top := 800;
    890   Y := Top; // 40
    891   X := Left; // 80
    892   j := 1;
    893   PrintDialog1 := TPrintDialog.Create(Application);
    894   if PrintDialog1.Execute then
    895   begin
    896     if Memo1.text = '' then
    897       Exit; // 文本为空 本次操作不会被执行
    898 
    899     With Printer do
    900     begin
    901       BeginDoc; // 另存的打印的文件名 如何实现  默认为 .jnt
    902       // Form2.Show;
    903       Canvas.Font := Memo.Font;
    904       // -------------------------------------------------------------------------
    905       // 打印文件名的标题
    906       // TitleStr:='无标题';
    907       posX := (PageWidth div 2) - Length(TitleStr) * 50; // x+1800;
    908       posY := (PageHeight * 6) div 100;
    909 
    910       // 第N页的标题
    911       PagesStr := Format('第 %d 页', [Printer.PageNumber]);
    912       Posx1 := (PageWidth div 2) - Length(PagesStr) * 50;
    913       posY1 := (PageHeight * 92) div 100;
    914       // -------------------------------------------------------------------------
    915       for i := 0 to Memo.Lines.Count - 1 do
    916       begin
    917         Canvas.TextOut(X, Y, Memo.Lines[i]); // TextOut(Left,Top,string);
    918         Y := Y + Memo.Font.Size * 10;
    919         // Memo.Font.Size*10为行间距 第1行与第2行的间距,2和3,3与4,...
    920 
    921         if (Y > PageHeight - Top) then
    922         begin
    923           Canvas.TextOut(posX, posY, TitleStr);
    924           for j := 1 to Printer.PageNumber do
    925           begin
    926             PagesStr := Format('第 %d 页', [j]);
    927             Canvas.TextOut(Posx1, posY1, PagesStr);
    928             // Form2.Label1.Caption := System.Concat(' 正在打印', #13#10, TitleStr,
    929             // #13#10, Format('第 %d 页', [j]));
    930             // if Form2.Tag = 1 then
    931             // begin
    932             // Abort;
    933             // Exit;
    934             // end;
    935           end;
    936           NewPage;
    937           Y := Top;
    938         end;
    939       end;
    940       Canvas.TextOut(posX, posY, TitleStr);
    941       Canvas.TextOut(Posx1, posY1, Format('第 %d 页', [j]));
    942       // Form2.Close;
    943       EndDoc;
    944     end;
    945   end;
    946 end;
    947 
    948 procedure TTextEditorForm.LoadConfig(Sender: TObject);
    949 begin
    950   ReadformState('MainForm', AppINI, Self);
    951 
    952   with TIniFile.Create(AppINI) do
    953   begin
    954     Memo1.Font.Name := ReadString('Memo', 'FontName', '宋体');
    955     Memo1.Font.Size := ReadInteger('Memo', 'Size', 10);
    956     mni_StatusBar.Checked := ReadBool('Other', 'StatueBarChecked', True);
    957     mni_WordWrap.Checked := ReadBool('Other', 'WordWrapChecked', True);
    958     Free;
    959   end;
    960 end;
    961 
    962 procedure TTextEditorForm.SaveConfig(Sender: TObject);
    963 begin
    964   WriteformState('MainForm', AppINI, Self);
    965 
    966   with TIniFile.Create(AppINI) do
    967   begin
    968     WriteString('Memo', 'FontName', Memo1.Font.Name);
    969     WriteInteger('Memo', 'Size', Memo1.Font.Size);
    970     WriteBool('Other', 'StatueBarChecked', mni_StatusBar.Checked);
    971     WriteBool('Other', 'WordWrapChecked', mni_WordWrap.Checked);
    972     Free;
    973   end;
    974 end;
    975 
    976 procedure TTextEditorForm.act_SetCaretPosExecute(Sender: TObject);
    977 begin
    978   if GetUserDefaultUILanguage() = $0804 then // SetUiCHS // Caption:='简体中文';
    979     StatusBar1.Panels[1].text := Format('  %s %d %s,%s %d %s ',
    980       [sLine, Memo1.CaretPos.Y + 1, scol, sLine, Memo1.CaretPos.X + 1, scol])
    981   else
    982     // SetUiEN;  //Caption:='英文';
    983     StatusBar1.Panels[1].text := Format('  %s %d ,%s %d ',
    984       [sLine, Memo1.CaretPos.Y + 1, scol, Memo1.CaretPos.X + 1]);
    985 end;
    986 
    987 end.
    View Code

      

  • 相关阅读:
    DELPHI IDFTP
    关于网络的一些小知识
    bootstrap弹出框
    GIt的简单使用
    Ubantu搭建虚拟环境
    python中的随机模块random
    python中动态创建类
    关于深浅拷贝的测试
    关于面向对象的属性访问
    多任务的使用模式
  • 原文地址:https://www.cnblogs.com/xe2011/p/3483809.html
Copyright © 2011-2022 走看看