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

📄 global.pas

📁 delphi 电子书阅读器 外观非常漂亮
💻 PAS
📖 第 1 页 / 共 2 页
字号:
			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('&nbsp;', ' ', strTextReadDo);
	ReplaceSubString('&quot;', '"', 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), PChar(GetWord('提示')), MB_ICONINFORMATION or Mb_OK);
end;

procedure Alert(Msg : string);
begin
	Application.MessageBox(PChar(Msg), PChar(GetWord('警告')), MB_ICONWARNING or Mb_OK);
end;

function Confirm(Msg : string) : boolean;
begin
	Result := (Application.MessageBox(PChar(Msg), PChar(GetWord('询问')), 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;

//---系统函数---
function GetAppPath : string;
begin
	Result := ExtractFilePath(ParamStr(0));
end;

function GetZipPassword(var s : string) : boolean;
begin
	with TFormZipPassword.Create(Application) do
	begin
		Result := (ShowModal = mrOk);
		s := EditPassword.Text;
		Free;
	end;
end;

end.

⌨️ 快捷键说明

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