构造HTML源代码:
procedure TFrmMain.makehtml;
var
liststr1,liststr2,checkNum1,checkNum2:string;
htmlFile:TextFile;
i,j,who,part1,part2,num1,probility:integer;
begin
liststr1:='';
liststr2:='';
htmlbody:='<HTML><meta http-equiv="Content-Type" content="text/html; charset=gb2312">';
htmlbody:=htmlbody+'<BODY background="bgpaper.gif"><TITLE>
投票系统</TITLE><p align="center"> </p>';
htmlbody:=htmlbody+'<INPUT TYPE=hidden NAME="LinkURL" VALUE="">';
htmlbody:=htmlbody+'<TABLE width="80%" align="center" border="1" bordercolor="#339966"><TR bordercolor="#FFFFFF">';
htmlbody:=htmlbody+'<TD ALIGN=center COLSPAN=2>';
。。。。。。。。。。。。
//
构造投票选项―――――――――――――――――――――
for j:=1 to 23 do
begin
checklist1[j]:=false;
checklist2[j]:=false;
end;
RandSeed:= inttime;
Randomize;
//
根据设置的投票选择概率来确定本次是否选择目标选项
if factor = 0 then
part1 := Random(10)
else part1 := Random(11);
num1:=part1;
while (part1>0) do
begin
who := Random(23)+1;
for j:=1 to 23 do
begin
if checklist1[who] then
break
else
begin
checklist1[who]:=true;
part1:=part1-1;
end;
end;
end;
probility := Random(100)+1;
if factor = 0 then
checklist2[2]:=true
else if (probility Mod factor) = 0 then
checklist2[2]:=true;
if checklist2[2] then
part2:=(10-num1)-1
else part2:=(10-num1);
while (part2 > 0 ) do
begin
who := Random(23)+1;
for j:=1 to 23 do
begin
if checklist2[who]then //
break
else
begin
checklist2[who]:=true;
part2:=part2-1;
end;
end;
end;
for j:=1 to 23 do
begin
if checklist1[j] then
begin
liststr1:=liststr1+checkedlist1[j];
checkNum1:=checkNum1+inttostr(j)+',';
end
else liststr1:=liststr1+uncheckedlist1[j];
if checklist2[j] then
begin
liststr2:=liststr2+checkedlist2[j];
checkNum2:=checkNum2+inttostr(j)+',';
end
else liststr2:=liststr2+uncheckedlist2[j];
end;
RichEdit1.Lines.Add('
第'+inttostr((times div 2)+1)+'
次投票结果:');
RichEdit1.Lines.Add('
第一组选中序号('+inttostr(num1)+'
个):'+checkNum1);
RichEdit1.Lines.Add('
第二组选中序号('+inttostr((10-num1))+'
个):'+checkNum2);
htmlbody:=htmlbody+liststr2;
htmlbody:=htmlbody+'<INPUT TYPE=hidden NAME="CHOICE2" VALUE="23"><TR bgcolor="#E7E8E3" bordercolor="#FFFFFF"><TD bgcolor="#CCCCCC"><TD ALIGN=center><INPUT name="sub" TYPE=submit VALUE="
提交"></TABLE></FORM></BODY></HTML>';
end;
|
procedure TFrmMain.loadHtml;
var
URL,v:OleVariant;
HTMLDocument:ihtmldocument2;
begin
try
makehtml;
except
on e:exception do
//showmessage('
出错!'+e.Message);
//exit;
end;
HTMLDocument := (WebBrowser1.Document as IHTMLDocument2);
v := VarArrayCreate([0, 0], varVariant);
v[0] := htmlbody; // Here's your HTML string
HTMLDocument.Write(PSafeArray(TVarData(v).VArray));
HTMLDocument.Close;
end;
|
procedure TFrmMain.submitForm;
var
obj:OleVariant;
doc: ihtmldocument2;
begin
doc:=(WebBrowser1 .Document as IHTMLDocument2);
if doc <> nil then
begin
//RichEdit1.text:=doc.body.innerText;
obj:=doc.all.item('sub',0);
obj.click;
end;
end;
|
function TFrmcheckproxy.ChangeProxy(const Proxy, Port,ByPass: string; const bEnabled: boolean = True): boolean;
var
reg: Tregistry;
info: INTERNET_PROXY_INFO;
Fproxy:string;
begin
Result := False;
FProxy:=Format('%s:%s',[Proxy,Port]);
reg := Tregistry.Create;
try
reg.RootKey := HKEY_CURRENT_USER;
if reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Internet Settings', True) then
begin
reg.Writestring('ProxyServer', Fproxy);
reg.WriteInteger('ProxyEnable', integer(bEnabled));
info.dwAccessType := INTERNET_OPEN_TYPE_PROXY;
info.lpszProxy := pchar(proxy);
info.lpszProxyBypass := pchar(ByPass);
InternetSetOption(nil, INTERNET_OPTION_PROXY, @info, SizeOf(Info));
InternetSetOption(nil, INTERNET_OPTION_SETTINGS_CHANGED, nil, 0);
// InternetSetOption(nil, INTERNET_OPTION_REFRESH, nil, 0);
// Sendmessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);
Result:=True;
end
finally
reg.CloseKey;
reg.free;
end;
end;
|