⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpasy1.pas

📁 文件名称:新曦 我的资源 搜索软件 源程序(Borland Delphi 7)说明
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Author:       Fran鏾is PIETTE
Creation:     January 31, 1998
Version:      1.01
Description:  This program shows how to use the THttpCli component to execute
              a list of request sequentialy or simultaneously.
              Simultaneous request are possible without using threads because
              the THttpCli component is fully event-driven and asynchronous.
              Data is not stroed. See the HttpTst sample program for an
              example of data store. We keep this sample as simple as possible.
EMail:        francois.piette@pophost.eunet.be    
              francois.piette@rtfm.be             http://www.rtfm.be/fpiette
Support:      Use the mailing list twsocket@rtfm.be See website for details.
Legal issues: Copyright (C) 1998 by Fran鏾is PIETTE
              Rue de Grady 24, 4053 Embourg, Belgium. Fax: +32-4-365.74.56
              <francois.piette@pophost.eunet.be>

              This software is provided 'as-is', without any express or
  	      implied warranty.  In no event will the author be held liable
              for any  damages arising from the use of this software.

              Permission is granted to anyone to use this software for any
              purpose, including commercial applications, and to alter it
              and redistribute it freely, subject to the following
              restrictions:

              1. The origin of this software must not be misrepresented,
                 you must not claim that you wrote the original software.
                 If you use this software in a product, an acknowledgment
                 in the product documentation would be appreciated but is
                 not required.

              2. Altered source versions must be plainly marked as such, and
                 must not be misrepresented as being the original software.

              3. This notice may not be removed or altered from any source
                 distribution.

Updates:
Feb 01, 1998 V1.01 Adedpted to be compatible with Delphi 1
             Save window position and size to ini file.

{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
unit HttpAsy1;

interface

uses
  WinTypes, WinProcs, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, HttpProt, IniFiles;

type
  THttpAsyForm = class(TForm)
    URLListBox: TListBox;
    Panel1: TPanel;
    Label1: TLabel;
    URLEdit: TEdit;
    AddButton: TButton;
    Panel2: TPanel;
    ExecButton: TButton;
    RemoveButton: TButton;
    DisplayMemo: TMemo;
    HttpCli1: THttpCli;
    ReplaceButton: TButton;
    ClearDisplayButton: TButton;
    HeaderCheckBox: TCheckBox;
    DataCheckBox: TCheckBox;
    SimultCheckBox: TCheckBox;
    AbortButton: TButton;
    procedure AddButtonClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure RemoveButtonClick(Sender: TObject);
    procedure ExecButtonClick(Sender: TObject);
    procedure HttpCli1RequestDone(Sender: TObject; RqType: THttpRequest;
      Error: Word);
    procedure URLListBoxClick(Sender: TObject);
    procedure ReplaceButtonClick(Sender: TObject);
    procedure ClearDisplayButtonClick(Sender: TObject);
    procedure HttpCli1HeaderData(Sender: TObject);
    procedure HttpCli1DocData(Sender: TObject; Buffer: Pointer;
      Len: Integer);
    procedure AbortButtonClick(Sender: TObject);
  private
    { D閏larations priv閑s }
    FInitialized  : Boolean;
    FIniFileName  : String;
    FCurrentItem  : Integer;
    FHttpCliList  : TList;      { For simultaneous requests }
    FFlagAbort    : Boolean;
    procedure StartNext;        { For sequential requests }
    procedure ExecSimultaneous;
    procedure ExecSequential;
    procedure HttpCliItemRequestDone(Sender: TObject; { For simult. requests }
                  RqType: THttpRequest; Error: Word);
  end;

var
  HttpAsyForm: THttpAsyForm;

implementation

{$R *.DFM}

const
    SectionData   = 'Data';
    KeyURL        = 'URLEdit';
    KeyCount      = 'Count';
    KeyList       = 'List';
    KeySimult     = 'Simultaneous';
    KeyHeader     = 'DisplayHeader';
    KeyData       = 'DisplayData';
    SectionWindow = 'Window';
    KeyTop        = 'Top';
    KeyLeft       = 'Left';
    KeyWidth      = 'Width';
    KeyHeight     = 'Height';


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{$IFDEF VER80}
function TrimRight(Str : String) : String;
var
    i : Integer;
begin
    i := Length(Str);
    while (i > 0) and (Str[i] = ' ') do
        i := i - 1;
    Result := Copy(Str, 1, i);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function TrimLeft(Str : String) : String;
var
    i : Integer;
begin
    if Str[1] <> ' ' then
        Result := Str
    else begin
        i := 1;
        while (i <= Length(Str)) and (Str[i] = ' ') do
            i := i + 1;
        Result := Copy(Str, i, Length(Str) - i + 1);
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
function Trim(Str : String) : String;
begin
    Result := TrimLeft(TrimRight(Str));
end;
{$ENDIF}


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure THttpAsyForm.FormCreate(Sender: TObject);
begin
    DisplayMemo.Clear;
    FCurrentItem := -1;
    FIniFileName := LowerCase(ExtractFileName(Application.ExeName));
    FIniFileName := Copy(FIniFileName, 1, Length(FIniFileName) - 3) + 'ini';
    FHttpCliList := TList.Create;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure THttpAsyForm.FormShow(Sender: TObject);
var
    IniFile : TIniFile;
    Count   : Integer;
    I       : Integer;
    URL     : String;
begin
    if not FInitialized then begin
        FInitialized           := TRUE;
        IniFile                := TIniFile.Create(FIniFileName);
        URLEdit.Text           := IniFile.ReadString(SectionData, KeyURL, '');
        HeaderCheckBox.Checked := (IniFile.ReadInteger(SectionData, KeyHeader, 0) <> 0);
        DataCheckBox.Checked   := (IniFile.ReadInteger(SectionData, KeyData,   0) <> 0);
        SimultCheckBox.Checked := (IniFile.ReadInteger(SectionData, KeySimult,   0) <> 0);
        Count                  := IniFile.ReadInteger(SectionData, KeyCount, 0);
        for I := 1 to Count do begin
            URL := IniFile.ReadString(SectionData, KeyList + IntToStr(I), '');
            if URL <> '' then
                URLListBox.Items.Add(URL);
        end;
        Top    := IniFile.ReadInteger(SectionWindow, KeyTop,    Top);
        Left   := IniFile.ReadInteger(SectionWindow, KeyLeft,   Left);
        Width  := IniFile.ReadInteger(SectionWindow, KeyWidth,  Width);
        Height := IniFile.ReadInteger(SectionWindow, KeyHeight, Height);
        IniFile.Free;
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure THttpAsyForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
var
    IniFile : TIniFile;
    I       : Integer;
    Count   : Integer;
begin
    IniFile := TIniFile.Create(FIniFileName);
    IniFile.WriteString(SectionData, KeyURL,  URLEdit.Text);
    IniFile.WriteInteger(SectionData, KeyHeader, Ord(HeaderCheckBox.Checked));
    IniFile.WriteInteger(SectionData, KeyData,   Ord(DataCheckBox.Checked));
    IniFile.WriteInteger(SectionData, KeySimult, Ord(SimultCheckBox.Checked));
    Count := URLListBox.Items.Count;
    IniFile.WriteInteger(SectionData, KeyCount, Count);
    for I := 1 to Count do
        IniFile.WriteString(SectionData, KeyList + IntToStr(I),
                            URLListBox.Items[I - 1]);
    IniFile.WriteInteger(SectionWindow, KeyTop,    Top);
    IniFile.WriteInteger(SectionWindow, KeyLeft,   Left);
    IniFile.WriteInteger(SectionWindow, KeyWidth,  Width);
    IniFile.WriteInteger(SectionWindow, KeyHeight, Height);
    IniFile.Destroy;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ Add an URL to the URL list box                                            }
procedure THttpAsyForm.AddButtonClick(Sender: TObject);
begin
    if Trim(URLEdit.Text) <> '' then
        URLListBox.Items.Add(URLEdit.Text);
    ActiveControl := URLEdit;
    URLEdit.SelectAll;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ Remove the selected URL from hte URL listbox                              }
procedure THttpAsyForm.RemoveButtonClick(Sender: TObject);
var
    Item : Integer;
begin
    Item := URLListBox.ItemIndex;
    if Item >= 0 then
        URLListBox.Items.Delete(Item);
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -