unit IdHttpDemoForm;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data;

type
  TWinForm = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    /// <summary>
    /// Required designer variable.
    /// </summary>
    Components: System.ComponentModel.Container;
    Panel1: System.Windows.Forms.Panel;
    Label1: System.Windows.Forms.Label;
    Label2: System.Windows.Forms.Label;
    TextBox1: System.Windows.Forms.TextBox;
    Button1: System.Windows.Forms.Button;
    TextBox2: System.Windows.Forms.TextBox;
    RichTextBox1: System.Windows.Forms.RichTextBox;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
    procedure Button1_Click(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;
  public
    constructor Create;
  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]

implementation

uses
  // if this doesn't compile you need to add the path to
  // the indy library to the project options
  IdHTTP,
  SysUtils;

{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWinForm.InitializeComponent;
begin
  Self.Panel1 := System.Windows.Forms.Panel.Create;
  Self.Label1 := System.Windows.Forms.Label.Create;
  Self.Label2 := System.Windows.Forms.Label.Create;
  Self.TextBox1 := System.Windows.Forms.TextBox.Create;
  Self.Button1 := System.Windows.Forms.Button.Create;
  Self.TextBox2 := System.Windows.Forms.TextBox.Create;
  Self.RichTextBox1 := System.Windows.Forms.RichTextBox.Create;
  Self.Panel1.SuspendLayout;
  Self.SuspendLayout;
  // 
  // Panel1
  // 
  Self.Panel1.Controls.Add(Self.TextBox2);
  Self.Panel1.Controls.Add(Self.Button1);
  Self.Panel1.Controls.Add(Self.TextBox1);
  Self.Panel1.Controls.Add(Self.Label2);
  Self.Panel1.Controls.Add(Self.Label1);
  Self.Panel1.Dock := System.Windows.Forms.DockStyle.Top;
  Self.Panel1.Location := System.Drawing.Point.Create(0, 0);
  Self.Panel1.Name := 'Panel1';
  Self.Panel1.Size := System.Drawing.Size.Create(520, 72);
  Self.Panel1.TabIndex := 0;
  // 
  // Label1
  // 
  Self.Label1.Location := System.Drawing.Point.Create(16, 8);
  Self.Label1.Name := 'Label1';
  Self.Label1.Size := System.Drawing.Size.Create(32, 16);
  Self.Label1.TabIndex := 0;
  Self.Label1.Text := 'URL';
  // 
  // Label2
  // 
  Self.Label2.Location := System.Drawing.Point.Create(16, 40);
  Self.Label2.Name := 'Label2';
  Self.Label2.Size := System.Drawing.Size.Create(40, 16);
  Self.Label2.TabIndex := 1;
  Self.Label2.Text := 'Proxy';
  // 
  // TextBox1
  // 
  Self.TextBox1.Anchor := (System.Windows.Forms.AnchorStyles(((System.Windows.Forms.AnchorStyles.Top 
      or System.Windows.Forms.AnchorStyles.Left) or System.Windows.Forms.AnchorStyles.Right)));
  Self.TextBox1.Location := System.Drawing.Point.Create(56, 8);
  Self.TextBox1.Name := 'TextBox1';
  Self.TextBox1.Size := System.Drawing.Size.Create(392, 20);
  Self.TextBox1.TabIndex := 2;
  Self.TextBox1.Text := 'http://www.indyproject.org';
  // 
  // Button1
  // 
  Self.Button1.Anchor := (System.Windows.Forms.AnchorStyles((System.Windows.Forms.AnchorStyles.Top 
      or System.Windows.Forms.AnchorStyles.Right)));
  Self.Button1.Location := System.Drawing.Point.Create(456, 8);
  Self.Button1.Name := 'Button1';
  Self.Button1.Size := System.Drawing.Size.Create(48, 23);
  Self.Button1.TabIndex := 3;
  Self.Button1.Text := 'Go';
  Include(Self.Button1.Click, Self.Button1_Click);
  // 
  // TextBox2
  // 
  Self.TextBox2.Anchor := (System.Windows.Forms.AnchorStyles(((System.Windows.Forms.AnchorStyles.Top 
      or System.Windows.Forms.AnchorStyles.Left) or System.Windows.Forms.AnchorStyles.Right)));
  Self.TextBox2.Location := System.Drawing.Point.Create(56, 38);
  Self.TextBox2.Name := 'TextBox2';
  Self.TextBox2.Size := System.Drawing.Size.Create(448, 20);
  Self.TextBox2.TabIndex := 4;
  Self.TextBox2.Text := 'proxy:8080';
  // 
  // RichTextBox1
  // 
  Self.RichTextBox1.Dock := System.Windows.Forms.DockStyle.Fill;
  Self.RichTextBox1.Location := System.Drawing.Point.Create(0, 72);
  Self.RichTextBox1.Name := 'RichTextBox1';
  Self.RichTextBox1.Size := System.Drawing.Size.Create(520, 227);
  Self.RichTextBox1.TabIndex := 1;
  Self.RichTextBox1.Text := 'HTML will be placed here';
  // 
  // TWinForm
  // 
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13);
  Self.ClientSize := System.Drawing.Size.Create(520, 299);
  Self.Controls.Add(Self.RichTextBox1);
  Self.Controls.Add(Self.Panel1);
  Self.Name := 'TWinForm';
  Self.Text := 'WinForm';
  Self.Panel1.ResumeLayout(False);
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure TWinForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TWinForm.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var
  LClient : TIdHTTP;
begin
  LCLient := TIdHTTP.create(nil);
  try
    if TextBox2.Text <> '' then
      begin
      LClient.ProxyParams.ProxyServer := copy(TextBox2.Text, 1, pos(':', TextBox2.Text)-1);
      if pos(':', TextBox2.Text) <> 0 then
        LClient.ProxyParams.ProxyPort := StrToInt(copy(TextBox2.Text, pos(':', TextBox2.Text)+1, $FF))
      else
        LClient.ProxyParams.ProxyPort := 80;
      end;
    RichTextBox1.Text := LClient.Get(TextBox1.Text);
  finally
    LCLient.Free;
  end;
end;

end.
