http://hi.baidu.com/eoknet/blog/item/88ef8de781952723b9382032.html
delphi中自动提交表单问题终结者,解决多FRAME网页的表单提交问题
某些聊天室是靠在线时间来加分的,我的程序是用来自动登陆某聊天室然后每隔一段时间发一次言以免掉线。
这当中需要解决自动提交表单问题,单FRAME的网页的提交问题我已经解决,但是对于多FRAME
的,在看了许多大富翁的回答后仍然解决不了,所以想求一帖能够真正解决这个问题。
这些方法我试了,都不行:
一、
procedure TForm1.Button3Click(Sender: TObject);
var
Htm:olevariant;
xh,i,k,Po:integer;
t:OleVariant;
IsFindPos:integer;
addqu,S:String;
sfind:integer;
begin
// try
// cancel:=false;
t := WebBrowser1.Document;
htm:=t.all.item(0,varEmpty);
for k := 0 to t.all.length - 1 do begin
if
(uppercase(t.all.item(k).tagName)='INPUT')and(uppercase(t.all.item(k).type)='TEXT')and(uppercase(t.all.item(k).name)='taklmsg') then begin t.all.item(k).value:='117';
break;
end;
end;
二、
//找到登录用户名的输入框
//o :=
WebBrowser1.oleobject.document.documentelement.document.frames.item(Index).document.all.item('username',0);
//o.value := 'TEST';
//找到登录密码的输入框
// o :=
WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex).document.all.item('LoginPassword',0);
// o.value := 'TEST'
//第一个表单提交
//
WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex).document.Forms.Item(0, 0).submit;
//WebBrowser1.oleobject.document.Forms.Item('login', 0).submit;
1:多个frames的输入,FrameIndex为Frame的序号
var
o : Olevariant;
begin
//找到登录用户名的输入框
o :=
WebBrowser.oleobject.document.documentelement.document.frames.item(FrameIndex).document.all.item('LoginUserID',0);
o.value := 'TEST';
//找到登录密码的输入框
o :=
WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex).document.all.item('LoginPassword',0);
o.value := 'TEST'
//第一个表单提交
WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex).document.Forms.Item(0, 0).submit;
{
//或者用指定表单名称提交
o :=WebBrowser.oleobject.document.documentelement.document.frames.item(FramIndex)..document.all.item('Login',0);
o.Click; //点击操作,对其它对象也可同样操作
}
end;
这种方法,我在用的时候提示说“停用“调用取消””(编译没有问题,执行EXE的时候提示的),这是什么意思,怎么解决
2:晕,少了..WebBrowser1.Navigate('你要注册的网址')........
3:to abtong :仔细看看再
4:我想终结这个帖子,不过上面两位老兄实在是不值我的份数啊。哪位大哥随便说点稍微有道理的让我把分散了吧。
5:接受答案了.
第二篇:delphi设计总结
一、Windows应用程序的调用
1.在USES中声明 ShellApi
2.在implementation的前面用VAR 定义例如: DirOpen: string='C:\生僻字数据库\帮助.doc'
3. 调用函数为: ShellExecute(0,'open',PAnsiChar(DirOpen),0,0,SW_SHOW );
Eg:
DirOpeneudcedit: string='C:\WINDOWS\system32\eudcedit.exe';
ShellExecute(0,'open',PAnsiChar(DirOpeneudcedit),0,0,SW_SHOW );
4.ExtractFilePath(Paramstr(0)) 可以随着文件夹的不同而打开
eg
ShellExecute(0,'open',PAnsiChar(''+ExtractFilePath(Paramstr(0))+'新编Windows API参考大全.doc'),0,0,SW_SHOW );
二、数据库操作
edit类的引用
(where后都要引号,insert时数字不用引号,其他包括日期都要用引号
''''+Edit1.text+''''引用过来的是已经带引号的字符串
Edit.txt直接引用过来的是数字,
1例如插入数字
Sql1:=edit1.text
Adoquery1.sql.add('insert table_name values('+sql1+ ') ')
2.插入日期或者字符
Sql1:= ''''+edit1.text+''''
Adoquery1.sql.add('insert table_name values('+sql1+ ') ')
3.where 后面的条件
Sql1:= ''''+edit1.text+''''
Sqlstr:= 'Select * from table_name where x='sql1
Adoquery1.sql.add (sqlstr)
数据库插图片:
procedure TForm1.Button1Click(Sender: TObject);
begin
if openpicturedialog1.Execute then
image1.Picture.LoadFromFile(openpicturedialog1.FileName);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
JPEGImage:TJPEGImage;//记得前面要引用JPEG
begin
JPEGImage:=TJPEGImage.Create; //创建JPEG图像对象
try
JPEGImage.LoadFromFile(OpenpictureDialog1.FileName); //从文件中装载jpg图像, ADOquery1.Edit;
DBImage1.Picture.Bitmap.Assign(JPEGImage); //将jpg导入
ADOquery1.Post;
finally
JPEGImage.Free; //释放对象
end;
end;
数据的插入
procedure Tnew.Button1Click(Sender: TObject);
var id,position,dname,price:string;
begin
if(edit1.text='')or(edit2.text='')or(edit3.text='')or
(edit4.text='')
then showmessage('请填写完整')
else begin
id:=edit1.Text;
position:=edit2.Text;
dname:=''''+edit3.Text+'''';
price:=edit4.Text;
try
adoquery1.sql.Clear;
adoquery1.SQL.add('insert into 碟 values('+id+','+position+','+dname+','+price+')'); adoquery1.ExecSQL;
showmessage('成功录入');
adoquery1.Close;
edit1.text:='';edit2.text:='';edit3.text:='';
edit4.text:='';
except
showmessage('输入的文字或数字格式不对')
end;
end;
end;
数据的删除
procedure Txinxiguanli.Button1Click(Sender: TObject);
var id,position,dname,price,shanchu:string;
begin
id:=dbedit1.text;
adoquery1.SQL.Clear;
shanchu:='delete from 碟 where 碟编号='+id+'';
adoquery1.SQL.Add(shanchu);
adoquery1.ExecSQL;
showmessage('成功删除');
adoquery1.close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 碟');
adoquery1.open;
数据的更新
procedure Txinxiguanli.Button2Click(Sender: TObject);
var id,position,dname,price,sql1:string;
begin
if(dbedit1.text='')or(dbedit2.text='')or(dbedit3.text='')or
(dbedit4.text='')
then showmessage('请填写完整')
else begin
id:=dbedit1.Text;
position:=dbedit2.Text;
dname:=''''+dbedit3.Text+'''';
price:=dbedit4.Text;
adoquery1.sql.Clear;
sql1:=' update 碟 set 碟编号='+id+' , 碟位号='+position+', 碟名='+dname+', 单价='+price+' where 碟编号='+id+' ';
adoquery1.sql.Add(sql1);
adoquery1.ExecSQL;
showmessage('已经保存修改的信息!') ;
adoquery1.close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from 碟');
adoquery1.open;
三、数据库的手动动连接
ACCESS
procedure Texchange.Button1Click(Sender: TObject);
var cStr : String; //连接数据库字串
begin
cStr := 'Provider=Microsoft.Jet.OLEDB.4.0;'+
'Data Source='+OpenDialog.FileName+';'+
'Persist Security Info=False';
If ADOConnection1.Connected then
ADOConnection1.Connected := false;
ADOConnection1.ConnectionString := cStr;
try
ADOConnection1.Connected := true;
except
Showmessage('请检查所选数据源是否正确,连接失败!');
Exit;
end;
Showmessage('成功连接——!'+OpenDialog.FileName);
end;
excel
procedure Texchange.Button1Click(Sender: TObject); var cStr : String; //连接数据库字串
begin
cStr := 'Provider=Microsoft.Jet.OLEDB.4.0;'+ 'Data Source='+OpenDg.FileName+';'+ 'Extended Properties=Excel 8.0;'+
'Persist Security Info=False';
If ADOConnection1.Connected then
ADOConnection1.Connected := false;
ADOConnection1.ConnectionString := cStr;
try
ADOConnection1.Connected := true;
except
Showmessage('请检查所选数据源是否正确,连接失败!'); Exit;
end;
Showmessage('成功连接——!'+OpenDialog.FileName); end;
四、新窗体的初始化
Application.CreateForm(T窗体名, 窗体名);
Eg:
窗体的显示和关闭
Application.CreateForm(TDataMod,DataMod);
ExchangeForm.ShowModal;
ExchangeForm.Destroy;