• “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

  • 相关阅读:
    ZAB 和 Paxos 算法的联系与区别?
    Spring支持的ORM?
    解释对象/关系映射集成模块?
    哪种依赖注入方式你建议使用,构造器注入,还是 Setter方法注入?
    我们能自己写一个容器类,然后使用 for-each 循环码?
    Struts2的Action中获取request对象的几种方式?
    Chroot 特性?
    String是最基本的数据类型吗?
    @Autowired 注解?
    比较HQL、Criteria、Native-SQL这三者做查询的区别,以及应该如何进行选择?
  • 原文地址:https://www.cnblogs.com/spider518/p/2143236.html
Copyright © 2020-2023  润新知