📄 global.pas
字号:
{
模块名称:全局变量定义
使用方法:无
返回值: 无
}
unit Global;
interface
uses SysUtils, Forms, Windows, Graphics, Registry, stdctrls;
//--------------------------------------常量------------------------------------
const
c_nAlarmMax = 4; //定时提醒最大数目
c_strRegSoundPath = 'Software\Tale\ReadBook\Sound'; //背景音乐目录
//---注册音乐设置---
c_strRegSoundFilename = '背景音乐文件';
c_strRegSoundRepeat = '重复播放';
//---系统常量---
c_strReturn = #13#10;
//--------------------------------------变量------------------------------------
var
//系统变量
//注册表变量
g_Regini : TRegIniFile;
//文件变量
g_strFilename : string = ''; //当前打开的文件名
//MP3变量
g_boolExistMP3 : Boolean = False; //是否存在MP3控件
//Zip变量
g_strZipPassDir : string; //zip文件临时解压目录(传递给unzip的目录)
g_strZipPassDirChar : array[1 .. 100] of Char; //用于得到系统的临时目录(如:c:\windows\temp)
g_strAppCurrentDir : string; //应用程序当前目录
g_boolSystemCall : Boolean = False; //系统调用标志(用于暂时屏蔽某些消息)
g_MousePoint : TPoint; //当前鼠标位置
//系统设置变量
g_boolChangeMax : Boolean = False; //是否改变最大化显示设置
g_boolChangeWindow : Boolean = False; //是否改变窗口设置
g_boolChangePage : Boolean = False; //是否改变页面设置
g_boolChangeYe : Boolean = False; //是否改变页码设置
g_boolChangePageDo : Boolean = False; //是否改变处理设置
g_boolChangeImage : Boolean = True; //是否改变背景设置
//书本设置变量
g_nBookLeft : integer; //窗口左位置
g_nBookTop : integer; //窗口上位置
g_nBookWidth : integer; //窗口宽度
g_nBookHeight : integer; //窗口高度
g_nYeCount : integer = 0; //总页码
g_nYeCurrent : integer = 0; //当前页码
g_nCountWord : integer = 0; //总字数
g_nOldYeCurrent : integer = 0; //翻页前的当前页码
//页面设置变量
g_boolMove : boolean; //移动窗口标志
g_boolResize : boolean; //改变窗口大小标志
g_boolPageMove : boolean; //点击页面移动窗口标志
g_boolPageYe : boolean; //点击页面翻页标志
g_boolMax : boolean; //最大化显示标志
g_boolMaxYe : boolean; //最大化显示翻页标志
g_boolAutoPageMove : boolean; //自动翻页标志
g_nAutoVal : integer; //自动翻页时间
g_boolBIG5 : boolean; //处理BIG5标志
g_boolGB : boolean; //处理GB标志
g_boolHtml : boolean; //处理Html标志
g_boolChap : boolean; //处理智能分段标志
g_boolHangD : boolean; //处理加倍行距标志
g_boolUnderLine : boolean; //显示下划线标志
g_nUnderLineColor : Integer; //下划线的颜色
g_nUnderLineOffset : Integer; //下划线的距离
g_nUnderLineThick : Integer; //下划线的宽度
//页码设置变量
g_strYe1Be : string; //页码1前缀
g_strYe1Af : string; //页码1后缀
g_strYe1Loc : string; //页码1位置参数
g_boolYe1Count : boolean; //页码1显示总页数
g_strYe2Be : string; //页码2前缀
g_strYe2Af : string; //页码2后缀
g_strYe2Loc : string; //页码2位置参数
g_boolYe2Count : boolean; //页码2显示总页数
//系统设置变量
g_boolBackImage : boolean; //使用背景图片标志
g_strBackImageFilename : string; //背景图片文件名
g_boolLabelImage : boolean; //使用书签图片标志
g_strLabelImageFilename : string; //书签图片文件名
g_boolShowTime : boolean; //显示时间标志
g_boolAlarm : array [1 .. c_nAlarmMax] of Boolean; //每次定时提醒标志
g_AlarmTime : array [1 .. c_nAlarmMax] of TDateTime; //每次定时提醒时间
g_strAlarmMsg : array [1 .. c_nAlarmMax] of string; //每次定时提醒内容
g_boolFlat : boolean; //浮动按钮标志
g_boolViewCtrl : boolean; //显示界面控制图标标志
g_boolChangeItem : boolean; //改变最新文件菜单标志
g_boolOpenCloseFile : boolean; //打开关闭时候的文件标志
g_boolClearLabel : boolean; //清除书签标志
g_boolClearNewItem : boolean; //清除最新文件菜单标志
g_boolAutoGB : boolean; //自动转换为GB/BIG5码
g_boolYeView : boolean; //显示页码标志
g_YeFont : TFont; //页码字体
g_PageFont : TFont; //页面字体
//--------------------------------------函数------------------------------------
//---转换函数---
function CheckTxt(CheckText : string) : string;
function HtmlToTxt(HtmlString : string) : string;
function ChapTxt(TxtString : string; ListChap1, ListChap2 : TListBox) : string;
procedure ReplaceSubString(SubString, ReplaceString : string; var s : string);
//---得到当前鼠标信息---
procedure GetCurrentMousePoint;
//---消息框---
procedure Prompt(Msg : string);
procedure Alert(Msg : string);
function Confirm(Msg : string) : boolean;
//---注册表---
function RegReadInt(Section, Ident : string; Default : integer = 0) : integer;
function RegReadStr(Section, Ident : string; Default : string = '') : string;
function RegReadBool(Section, Ident : string; Default : boolean = False) : boolean;
procedure RegWriteInt(Section, Ident : string; Value : integer = 0);
procedure RegWriteStr(Section, Ident : string; Value : string = '');
procedure RegWriteBool(Section, Ident : string; Value : boolean = False);
procedure RegEraseSection(Section : string);
//--------------------------------------实现------------------------------------
implementation
//---转换函数---
function CheckTxt(CheckText : string) : string;
var strTextReadDo : string; //处理一部分文本框的字符串
boolEndChange : Boolean; //处理结束标志
nChangeIndex : integer; //转换位置
j, k, L : integer;
begin
strTextReadDo := CheckText; //初始化转换文本框
boolEndChange := False; //写标志:没有完成处理
nChangeIndex := 1; //从第1位开始搜索
while not boolEndChange do
begin
//搜索错误的换行
L := Length(strTextReadDo);
j := pos(#10, Copy(strTextReadDo, nChangeIndex, L - nChangeIndex + 1));
k := pos(#13, Copy(strTextReadDo, nChangeIndex, L - nChangeIndex + 1));
if ((j = 0) and (k = 0)) or (nChangeIndex > L) then
boolEndChange := True //结束搜索
else
begin
if ((j < k) or (k = 0)) and (j <> 0) then
begin //非正常换行,在前插入#13
Insert(#13, strTextReadDo, nChangeIndex + j - 1);
inc(j);
end
else
if k <> j - 1 then
begin //非正常换行,在后插入#10
Insert(#10, strTextReadDo, nChangeIndex + k);
j := k + 1;
end;
//搜索重定位
inc(nChangeIndex, j);
end;
end;
//得到转换后的文本
Result := strTextReadDo;
end;
function HtmlToTxt(HtmlString : string) : string;
var strTextReadDo : string; //处理一部分文本框的字符串
boolEndChange : Boolean; //处理结束标志
nChangeIndex : integer; //转换位置
strSelString : string; //选择的部分
j, k, L : integer;
begin
strTextReadDo := HtmlString; //初始化转换文本框
boolEndChange := False; //写标志:没有结束处理
nChangeIndex := 1; //从第1位开始搜索
//替换指定的字符
ReplaceSubString(' ', ' ', strTextReadDo);
ReplaceSubString('"', '"', strTextReadDo);
ReplaceSubString('<br>', c_strReturn, strTextReadDo);
ReplaceSubString('<p>', c_strReturn, strTextReadDo);
//替换Html字符
while not boolEndChange do
begin
//搜索<...>内容
L := Length(strTextReadDo);
j := pos('<', Copy(strTextReadDo, nChangeIndex, L - nChangeIndex + 1));
k := pos('>', Copy(strTextReadDo, nChangeIndex, L - nChangeIndex + 1));
if (j = 0) or (k = 0) or (nChangeIndex > L) then
boolEndChange := True
else
begin
if (j < k) then
begin
//得到选择内容
strSelString := LowerCase(Copy(strTextReadDo,
nChangeIndex + j - 1,
k - j + 1));
//处理<...>内容
if strSelString = '' then
begin
//
end
else
begin
Delete(strTextReadDo,
nChangeIndex + j - 1,
k - j + 1);
//删除后面的回车、换行
if LowerCase(Copy(strTextReadDo, nChangeIndex + j - 1, 2)) = c_strReturn then
Delete(strTextReadDo,
nChangeIndex + j - 1,
2);
dec(j);
end;
end
else
begin
dec(j);
end;
//搜索重定位
inc(nChangeIndex, j);
end;
end;
//得到转换后的文本
Result := strTextReadDo;
end;
function ChapTxt(TxtString : string; ListChap1, ListChap2 : TListBox) : string;
var boolDoFlag : Boolean; //处理判断
strChapBehindFlag, strChapBehindFlag1 : string; //段后内容
strChapBehindInsert, strChapBehindInsert1 : string; //插入段后内容
nChapBehindFlagLength, nChapBehindInsertLength : integer; //段后内容长度、插入段后内容长度
strTextReadDo : string; //处理一部分文本框的字符串
boolEndChange : Boolean; //处理结束标志
nChangeIndex : integer; //转换位置
strSelString : string; //选择的部分
j, k, L : integer;
begin
strChapBehindFlag := ' '; //段后内容(全角)
strChapBehindFlag1 := ' '; //段后内容(半角)
nChapBehindFlagLength := 2; //段后内容长度
strChapBehindInsert := ' '; //插入段后内容长度(全角)
strChapBehindInsert1 := ' '; //插入段后内容长度(半角)
nChapBehindInsertLength := 4; //插入段后内容长度
strTextReadDo := TxtString; //初始化转换文本框
boolEndChange := False; //写标志:没有结束处理
nChangeIndex := 1; //从第1位开始搜索
while not boolEndChange do
begin
L := Length(strTextReadDo);
j := pos(c_strReturn, Copy(strTextReadDo,
nChangeIndex,
L - nChangeIndex + 1));
if (j = 0) or (nChangeIndex > L) then
boolEndChange := True
else
begin
//判断选择内容
boolDoFlag := True;
//判断段前内容
//判断全角
strSelString := LowerCase(Copy(strTextReadDo,
nChangeIndex + j - 3,
2));
for k := 1 to ListChap2.Items.Count do
if strSelString = ListChap2.Items[k - 1] then
begin //是结束标点符号
boolDoFlag := False;
//添加空格
strSelString := LowerCase(Copy(strTextReadDo,
nChangeIndex + j + 1,
nChapBehindInsertLength));
if (strSelString <> strChapBehindInsert) and (strSelString <> strChapBehindInsert1) then
begin //添加空格
Insert(strChapBehindInsert,
strTextReadDo,
nChangeIndex + j + 1);
inc(j, nChapBehindInsertLength);
end;
inc(j);
end;
//判断半角
if boolDoFlag then
begin
strSelString := LowerCase(Copy(strTextReadDo,
nChangeIndex + j - 2,
1));
for k := 1 to ListChap1.Items.Count do
if strSelString = ListChap1.Items[k - 1] then
begin //是结束标点符号
boolDoFlag := False;
strSelString := LowerCase(Copy(strTextReadDo,
nChangeIndex + j + 1,
nChapBehindInsertLength));
if (strSelString <> strChapBehindInsert) and (strSelString <> strChapBehindInsert1) then
begin //添加空格
Insert(strChapBehindInsert,
strTextReadDo,
nChangeIndex + j + 1);
inc(j, nChapBehindInsertLength);
end;
inc(j);
end;
end;
//判断段后空格
if boolDoFlag then
begin
strSelString := Copy(strTextReadDo,
nChangeIndex + j + 1,
nChapBehindFlagLength);
if (strSelString = strChapBehindFlag) or (strSelString = strChapBehindFlag1) then
begin
boolDoFlag := False;
inc(j, nChapBehindFlagLength + 1);
end;
end;
//处理换行内容
if boolDoFlag then
begin //智能合并
Delete(strTextReadDo,
nChangeIndex + j - 1,
2);
dec(j);
end;
//搜索重定位
inc(nChangeIndex, j);
end;
end;
//得到转换后的文本
Result := strTextReadDo;
end;
procedure ReplaceSubString(SubString, ReplaceString : string; var s : string);
var nIndex, nPos : integer;
begin
nPos := 1;
nIndex := Pos(LowerCase(SubString), LowerCase(Copy(s, nPos, Length(s) - nPos + 1)));
while (nIndex > 0) do
begin
Delete(s, nIndex + nPos - 1, Length(SubString)); //删除指定的字符串
Insert(ReplaceString, s, nIndex + nPos - 1); //插入替换的字符串
inc(nPos, nIndex - 1 + Length(ReplaceString)); //重新定位起始点
nIndex := Pos(LowerCase(SubString), LowerCase(Copy(s, nPos, Length(s) - nPos + 1)));
end;
end;
//---得到鼠标当前位置---
procedure GetCurrentMousePoint();
begin
GetCursorPos(g_MousePoint);
end;
//---消息框---
procedure Prompt(Msg : string);
begin
Application.MessageBox(PChar(Msg), '提示', MB_ICONINFORMATION or Mb_OK);
end;
procedure Alert(Msg : string);
begin
Application.MessageBox(PChar(Msg), '警告', MB_ICONWARNING or Mb_OK);
end;
function Confirm(Msg : string) : boolean;
begin
Result := (Application.MessageBox(PChar(Msg), '询问', MB_ICONQUESTION or MB_OKCancel) = Id_Ok);
end;
//---注册表---
function RegReadInt(Section, Ident : string; Default : integer = 0) : integer;
begin
Result := g_Regini.ReadInteger(Section, Ident, Default);
end;
function RegReadStr(Section, Ident : string; Default : string = '') : string;
begin
Result := g_Regini.ReadString(Section, Ident, Default);
end;
function RegReadBool(Section, Ident : string; Default : boolean = False) : boolean;
begin
Result := g_Regini.ReadBool(Section, Ident, Default);
end;
procedure RegWriteInt(Section, Ident : string; Value : integer = 0);
begin
g_Regini.WriteInteger(Section, Ident, Value);
end;
procedure RegWriteStr(Section, Ident : string; Value : string = '');
begin
g_Regini.WriteString(Section, Ident, Value);
end;
procedure RegWriteBool(Section, Ident : string; Value : boolean = False);
begin
g_Regini.WriteBool(Section, Ident, Value);
end;
procedure RegEraseSection(Section : string);
begin
g_Regini.EraseSection(Section);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -