我是如何使用CnPack背英语句子的
CnPack的脚本功能很强大,照着例子写了一小段代码,从一个文本文件每次读取一行,简答设置一下即可实现每次编译代码前都会弹出对话框显示英语句子。
虽然功能简单,但是很好用呀,希望对爱好学习英语的程序员有帮助。
代码如下:
program ShowEnglishSentence;
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
procedure ShowSentence(const AStr:string);
var
sTemp:string;
begin
sTemp:=Trim(AStr);
if sTemp<>'' then
begin
ShowMessage(sTemp);
end;
end;
var
sl:TStringList;
sTemp:string;
iNo:Integer;
const
playno='PlayNo:';//记录已经读取的行号,会被写入到文本文件的最后一行。
EFile='D:\ebooks\English\英语听力-口语8000句\01.在家中.lrc'; //需要替换成自己的文本文件。
begin
sl := TStringList.Create();
try
if not FileExists(EFile) then
begin
ShowSentence(EFile+' not found!');
Exit;
end;
sl.LoadFromFile(EFile);
if sl.Count=0 then Exit;
sTemp:=sl[sl.Count -1];
if Copy(sTemp,1,Length(playno))=playno then
begin
sTemp:=Copy(sTemp,Length(playno)+1,MaxInt);
end
else
begin
sl.Add(playno+'0');
sTemp:='0';
end;
iNo:=StrToIntDef(sTemp,0);
if iNo>=sl.Count then
begin
iNo:=0;
end;
sTemp:=sl[iNo];
iNo:=iNo+1;
sl[sl.Count -1]:=playno+IntToStr(iNo);
sl.SaveToFile(EFile);
ShowSentence(sTemp);
finally
sl.Free;
end;
end.
将代码另存为ShowEnglishSentence.pas即可。
接下来,需要配置一下CnPack的脚本扩展专家。
1)点击增加按钮,添加一个新的脚本。
2)选择刚刚保存的ShowEnglishSentence.pas文件。
3)【手动执行脚本时需要确认】这项不要选择,要不然没有每次都会弹出一个运行脚本的确认对话框。
4)勾选【smBeforeCompile】。
5)关闭设置窗体。
快点试试效果吧。
浙公网安备 33010602011771号