1.delphi 谁帮我翻译下这段代码——高分
2.delphi有没有类似ASP中server.htmlencode和htmldecode的源码p2p网络借贷系统源码函数?
3.delphi 打开本机相对路径的.html文件
delphi 谁帮我翻译下这段代码——高分
//是个基于多线程的模拟浏览器的 Get 和Post 方法的类,具体我也不大清楚,,
//也只能大概说说了.
unit web;
interface
uses
Classes,IdHTTP,SysUtils,IdCookieManager,IdMultipartFormData
,windows;
//类的声明
type
TWeb = class(TThread)
private
protected
procedure Execute; override; //重写父类TThread的Exeecute方法.
public
mode: Integer; //标志位:根据这个判断是Get还是Post
url: string; //Url地址
idhttp: TIDHttp; //Indy 的http组件
sl: TStringList;
mpfDS: TIdMultiPartFormDataStream; //用这个控件实现 Stream的提交方法的.
flag: Boolean; //标志位,代码没有读懂,不知道是控制什么状态的
err,html: string;
stm: TMemoryStream;
constructor create; //构建函数
end;
implementation
//构造函数 ,全是初始化声明的类,没啥好说的.
constructor TWeb.create;
begin
idhttp := TIDHttp.Create(nil);
idhttp.CookieManager := TIDCookieManager.Create(idhttp);
sl := TStringList.Create();
mpfDS := TIdMultiPartFormDataStream.Create();
stm := TMemoryStream.Create();
FreeOnTerminate := True; //这也是个标志位: 当中断时候释放
inherited Create(True);
end;
//重写父类TThread的Exeecute方法.
procedure TWeb.Execute;
begin
while not Terminated do
begin
Sleep();
if Suspended then continue; //不懂,估计是多线程的同步处理?
flag := True;
err := '';
html := '';
//根据mode判断执行的功能 1 :Get文本 2:Get 流 3 提交数组ts是上面定义的一个数组 4 提交Stream,估计是提交类似,文件一类的东西
Case mode of //1:get text 2:get stream 3:post ts 4:post mpfDS
1:
begin
try
html := idhttp.Get(url); //这个用Indy的idhttp 获取URL地址的内容.文本方式.
except
on e:exception do begin
flag := False;
err := e.Message;
end;
end;
end;
2:
begin
stm.Clear();
try
idhttp.Get(url,stm); //用Indy的idhttp 获取URL内容 ,Stream方式
except
on e:exception do begin
flag := False;
err := e.Message;
end;
end;
end;
//也是用Indy的idhttp实现提交功能, 没时间详细些了,lz可以查看INDY组件IDHTTP的控件的详细使用方法.
//可以hi我再进行交流...
3:
begin
try
html := idhttp.Post(url,sl);
except
on e:exception do begin
flag := False;
err := e.Message;
end;
end;
end;
4:
begin
try
html := idhttp.Post(url,mpfDS);
except
on e:exception do begin
flag := False;
err := e.Message;
end;
end;
end;
5:
begin
idhttp.Request.ContentType := 'application/x-www-form-urlencoded';
try
html := idhttp.Post(url,stm);
except
on e:exception do begin
flag := False;
err := e.Message;
end;
end;
end;
end;
if (html<>'') and (Pos('utf',LowerCase(idhttp.Response.ContentType))>0) then
html := Utf8Decode(html);
Suspended := True;
end;
idhttp.Free();
sl.Free();
mpfDS.Free();
stm.Free(); //释放...
end;
end.
delphi有没有类似ASP中server.htmlencode和htmldecode的函数?
自己写.
function HTMLEncode(const AStr: String): String;
const
Convert = ['&','<','>','"'];
var
Sp, Rp: PChar;
begin
SetLength(Result, Length(AStr) * );
Sp := PChar(AStr);
Rp := PChar(Result);
while Sp^ <> #0 do
begin
case Sp^ of
'&': begin
FormatBuf(Rp^, 5, '&', 5, []);
Inc(Rp,4);
end;
'<',
'>': begin
if Sp^ = '<' then
FormatBuf(Rp^, 4, '<', 4, [])
else
FormatBuf(Rp^, 4, '>', 4, []);
Inc(Rp,3);
end;
'"': begin
FormatBuf(Rp^, 6, '"', 6, []);
Inc(Rp,5);
end;
else
Rp^ := Sp^
end;
Inc(Rp);
Inc(Sp);
end;
SetLength(Result, Rp - PChar(Result));
end;
function HTMLDecode(const AStr: String): String;
var
Sp, Rp, Cp, Tp: PChar;
S: String;
I, Code: Integer;
begin
SetLength(Result, Length(AStr));
Sp := PChar(AStr);
Rp := PChar(Result);
Cp := Sp;
try
while Sp^ <> #0 do
begin
case Sp^ of
'&': begin
Cp := Sp;
Inc(Sp);
case Sp^ of
'a': if AnsiStrPos(Sp, 'amp;') = Sp then { do not localize }
begin
Inc(Sp, 3);
Rp^ := '&';
end;
'l',
'g': if (AnsiStrPos(Sp, 'lt;') = Sp) or (AnsiStrPos(Sp, 'gt;') = Sp) then { do not localize }
begin
Cp := Sp;
Inc(Sp, 2);
while (Sp^ <> ';') and (Sp^ <> #0) do
Inc(Sp);
if Cp^ = 'l' then
Rp^ := '<'
else
Rp^ := '>';
end;
'q': if AnsiStrPos(Sp, 'quot;') = Sp then { do not localize }
begin
Inc(Sp,4);
Rp^ := '"';
end;
'#': begin
Tp := Sp;
Inc(Tp);
while (Sp^ <> ';') and (Sp^ <> #0) do
Inc(Sp);
SetString(S, Tp, Sp - Tp);
Val(S, I, Code);
Rp^ := Chr((I));
end;
else
raise EConvertError.CreateFmt(sInvalidHTMLEncodedChar,
[Cp^ + Sp^, Cp - PChar(AStr)])
end;
end
else
Rp^ := Sp^;
end;
Inc(Rp);
Inc(Sp);
end;
except
on E:EConvertError do
raise EConvertError.CreateFmt(sInvalidHTMLEncodedChar,
[Cp^ + Sp^, Cp - PChar(AStr)])
end;
SetLength(Result, Rp - PChar(Result));
end;
delphi 打开本机相对路径的.html文件
如果只是实现你说的,你的DELPHI工程和 HTML文件放在一起的话,就可以这样调用:
//单元接口引用 SHELLAPI;
shellexecute(handle, nil, pchar(extractfilepath(application.ExeName)+'\index.html'), nil, nil, sw_showNormal);
2024-11-28 07:13
2024-11-28 06:50
2024-11-28 06:44
2024-11-28 05:22
2024-11-28 05:07
2024-11-28 05:01