构造HTML源代码: procedure TFrmMain.makehtml;var liststr1,liststr2,checkNum1,checkNum2:string; htmlFile:TextFile; i,j,who,part1,part2,num1,probility:integer;begin liststr1:=''; liststr2:=''; htmlbody:='HTMLmeta http-equiv="Content-Type" content="text/html; charset=gb2312"'; htmlbody:=htmlbody+'BODY background="bgpaper.gif"TITLE投票系统/TITLEp 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 (part10) 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="CHOICE 2" VALUE="23"TR bgcolor="#E7E8E3" bordercolor="#FFFFFF"TD bgcolor="#CCCCCC"TD ALIGN=centerINPUT name="sub" TYPE=submit VALUE="提交"/TABLE/FORM/BODY/HTML'; end;
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)把生成的HTML载入Webbrowser,生成网页表格 2procedure 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;
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)然后模拟点击网页的提交按钮,提交表单数据:表格 3procedure 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;
设置代理服务器:表格 4function 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('SoftwareMicrosoftWindowsCurrentVersionInternet 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;
最后界面: 图表 1 主界面(使用了一个界面的第三方包-SUIPackage) 图表 2图表 1 主界面,同时查看投票过程和结果(使用了一个界面的第三方包-SUIPackage)