⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umain.pas

📁 PASSOLO字典替换工具 原创作品。文本文件字符串操作程序。
💻 PAS
字号:
unit Umain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls, ExtCtrls, XPMan;

type
  TMainForm = class(TForm)
    LabeledEdit1: TLabeledEdit;
    LabeledEdit2: TLabeledEdit;
    LE_Target: TLabeledEdit;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    Btn_start: TBitBtn;
    Btn_ReSelect: TBitBtn;
    Btn_Close: TBitBtn;
    LE_Start_Line: TLabeledEdit;
    LE_Next_Line: TLabeledEdit;
    Timer1: TTimer;
    Label1: TLabel;
    Bevel1: TBevel;
    Bevel2: TBevel;
    XPManifest1: TXPManifest;
    procedure Btn_CloseClick(Sender: TObject);
    procedure Btn_ReSelectClick(Sender: TObject);
    procedure LE_Start_LineKeyPress(Sender: TObject; var Key: Char);
    procedure LE_Next_LineKeyPress(Sender: TObject; var Key: Char);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure Btn_startClick(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    procedure SetControls;
    procedure ProcessTxt;
    { Public declarations }
  end;

var
  MainForm: TMainForm;
  StartLine, NextLine : integer;  //启始行号,行间隔

implementation

{$R *.dfm}

procedure TMainForm.Btn_CloseClick(Sender: TObject);
begin
  Close;
end;

procedure TMainForm.Btn_ReSelectClick(Sender: TObject);
begin
  if Application.MessageBox('确认重选?', 'Info', MB_ICONQUESTION+MB_YESNO) = IDNO then exit;
  LabeledEdit1.Clear;
  LabeledEdit2.Clear;
  LE_Start_Line.Clear;
  LE_Next_Line.Clear;
  LE_Target.Clear;
end;

procedure TMainForm.LE_Start_LineKeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in ['0'..'9', #8]) then
     key := #0;
end;

procedure TMainForm.LE_Next_LineKeyPress(Sender: TObject; var Key: Char);
begin
  if not (key in ['0'..'9', #8]) then
     key := #0;
end;

procedure TMainForm.SpeedButton1Click(Sender: TObject);
begin
   if OpenDialog1.Execute then
   begin
      if OpenDialog1.FileName <> LabeledEdit2.Text then
         LabeledEdit1.Text := OpenDialog1.FileName
      else
         Application.MessageBox('英文版和中文版文件不能为同一个文件!', '错误', MB_ICONERROR);
   end;
end;

procedure TMainForm.SpeedButton2Click(Sender: TObject);
begin
   if OpenDialog1.Execute then
   begin
      if OpenDialog1.FileName <> LabeledEdit1.Text then
         LabeledEdit2.Text := OpenDialog1.FileName
      else
         Application.MessageBox('英文版和中文版文件不能为同一个文件!', '错误', MB_ICONERROR);      
   end;
end;

procedure TMainForm.SetControls;
begin
  Btn_start.Enabled := not Btn_start.Enabled;
  Btn_ReSelect.Enabled := not Btn_ReSelect.Enabled;
  Btn_Close.Enabled := not Btn_Close.Enabled;
  LabeledEdit1.Enabled := not LabeledEdit1.Enabled;
  LabeledEdit2.Enabled := not LabeledEdit2.Enabled;
  LE_Start_Line.Enabled := not LE_Start_Line.Enabled;
  LE_Next_Line.Enabled := not LE_Next_Line.Enabled;
  LE_Target.Enabled := not LE_Target.Enabled;
  SpeedButton1.Enabled := not SpeedButton1.Enabled;
  SpeedButton2.Enabled := not SpeedButton2.Enabled;
  SpeedButton3.Enabled := not SpeedButton3.Enabled;
end;

procedure TMainForm.Btn_startClick(Sender: TObject);
begin
  if not (fileexists(LabeledEdit1.Text) and
     fileexists(LabeledEdit2.Text) ) then
  begin
     Application.MessageBox('原始字典文件不存在!请检查!', '错误', MB_ICONERROR);
     exit;
  end;
  if (LE_Start_Line.Text = '') and (LE_Next_Line.Text = '') and (LE_Target.Text = '') then
  begin
     Application.MessageBox('有信息未输入完整!', '错误', MB_ICONERROR);
     exit;
  end;
  if Application.MessageBox('确认开始制作吗?', '开始', MB_ICONQUESTION+MB_YESNO) = IDNO then exit;

  try
    StartLine := StrToInt(LE_Start_Line.Text);
  except
    StartLine := 11;
  end;
  try
    NextLine := StrToInt(LE_Next_Line.Text);
  except
    NextLine := 5;
  end;

  SetControls;
  Timer1.Enabled := True;
end;

procedure TMainForm.SpeedButton3Click(Sender: TObject);
begin
  if SaveDialog1.Execute then
  begin
     if FileExists(SaveDialog1.FileName) then
        if application.MessageBox(Pchar('文件 "'+ExtractFileName(SaveDialog1.FileName)+'" 已经存在,覆盖它吗?'), '确认', MB_ICONQUESTION+MB_YESNO)=IDNO then exit;
     LE_Target.Text := SaveDialog1.FileName;
  end;
end;

procedure TMainForm.ProcessTxt;
 var F1, F2, F3 : TextFile;
     S1, S2, S3 : String;
     File1, File2, File3 : String;
     i : integer; //行号指针
     j : integer;
begin
  File1 := LabeledEdit1.Text;
  File2 := LabeledEdit2.Text;
  File3 := LE_Target.Text;

  //StartLine, NextLine
  AssignFile(F1, File1);
  Reset(F1); //只读
  AssignFile(F2, File2);
  Reset(F2); //只读
  AssignFile(F3, File3);
  ReWrite(F3);  //覆盖文件(创建文件)
  i := 0; //写启始行
  while i <= StartLine do  //先将StartLine-1行文件头写入新文件
  begin
    Readln(F1, S1);
    Readln(F2, S2); //中文版文件也要同步读取
    WriteLn(F3, S1);  //将英文版文件头写入新文件
    inc(i);
  end;

  while not eof(F1) do
  begin
     for j := 1 to NextLine-1 do //1..4
     begin
       Readln(F1, S1);
       Readln(F2, S2);
       WriteLn(F3, S1);
       inc(i);
     end;
     Readln(F1, S1);
     Readln(F2, S2);
     WriteLn(F3, S2);
     inc(i);
     Application.ProcessMessages;
  end;

  CloseFile(F1);
  CloseFile(F2);
  CloseFile(F3);
end;

procedure TMainForm.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  //处理.......
  try
    ProcessTxt;
  except
    Application.MessageBox('处理过程中出错!', '错误', MB_ICONERROR);
    SetControls;
    exit;
  end;


  //完成
  SetControls;
  Update;
  Application.MessageBox('处理完毕!', '完成', MB_ICONINFORMATION);
end;

end.

⌨️ 快捷键说明

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