“58信息定时发布器” 编写纪要

1。数据库中随机抽取记录:

  try
    if AQry1.Active then AQry1.Close;
    AQry1.Open;
    //AQry.First;
    Randomize;
    AQry1.MoveBy(Random(AQry1.RecordCount - 1));
  finally
    Str2 := AQry1.FieldByName('title').AsString;
    Str1 := AQry1.FieldByName('content').AsString;
    AQry1.Close;
  end;

2。执行JS脚本的函数:

function ExecJS(WebBrowser:TWebBrowser; Code: string):Variant;
var
  Document:IHTMLDocument2;
  Window:IHTMLWindow2;
begin
  // execute javascript in webbrowser
  Document:=WebBrowser.Document as IHTMLDocument2;
  if not Assigned(Document) then Exit;
  Window:=Document.parentWindow;
  if not Assigned(Window) then Exit;
  try
    Result:=Window.execScript(Code,'JavaScript');
  except
    on E:Exception do raise Exception.Create('Javascript error '+E.Message+' in: '#13#10+Code);
  end;
end;

3。截取字符串的函数:

function GetHref(StrSource, StrBegin, StrEnd: string): string;
var
  HrefStart,HrefEnd:integer;
begin
  HrefStart:=AnsiPos(strbegin,strsource)+length(strbegin);
  HrefEnd:=AnsiPos(strend,strsource);
  result:=copy(strsource,HrefStart,HrefEnd-HrefStart);
end;

4,。获取当前WebBrowser的URL:

LoginWeb.LocationURL;

5。添加记录到ListView中:

      With ListView1.Items.Add do
      begin
        Caption := '成功';
        ImageIndex := 0;
        SubItems.Add(UrlStr);
      end;

6。操作DBGridEh:

原来只要代开了数据库,设置相关属性,就可以自己获取数据库的中数据,和那个Delphi自带的DBGrid差不多!

7。判断数据库中某项是否应存在:

  Str1 := trim(Edit1.Text);
  AQuery.SQL.Clear;
  AQuery.SQL.Add('select * from webUser where UserName=:str1');
  AQuery.Parameters.ParamByName('str1').Value := Str1;
  Aquery.Open;

  if AQuery.RecordCount = 0 then

  begin
    ShowMessage('用户名不能重复!');
  end;

8。对网页中某个Element的class进行操作:

if Uppercase(fDiv.all.item(i).ClassName) = 'EDITOR' then

begin

//执行某些操作!

end;

http://xtty.xoom.it/58/index.html

posted on 2011-08-17 16:04  Supper  阅读(646)  评论(0编辑  收藏  举报

导航