Ver Mensaje Individual
  #12  
Antiguo 12-09-2005
Avatar de Crandel
[Crandel] Crandel is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Parana, Argentina
Posts: 1.475
Reputación: 23
Crandel Va por buen camino
Antuan, ahora que ya casi tienes el código, te recomiendo que avances al paso siguiente y crees una clase a que resuelva tu problema.

Aca te dejo algunas correcciones a tu código (los comentarios son todos códigos que no deben ir):
Código Delphi [-]
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Sockets, ScktComp;
type
    TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Edit1: TEdit;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    ClientSocket1: TClientSocket;
    // lo cambie
    procedure PeticionWeb(url: string);
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
  ClientSocket1 := TClientSocket.Create(Self);
  ClientSocket1.ClientType := ctNonBlocking;
  //  ClientSocket1.Name:= 'ClientSocket1';   no modificar el name
  //  ClientSocket1.Host := 'www.auna.com'; para que asignarle una propiedad que vas a modificar despues
  ClientSocket1.Port := 80;
  ClientSocket1.OnRead:= ClientSocket1Read;
  ClientSocket1.Active := False;
end;
// esta función siempre devuelve una cadena vacia
// tampoco va el var
//function TForm1.PeticionWeb(var url: string):string;
procedure TForm1.PeticionWeb(url: string);
begin
  result:= ' ';
  with ClientSocket1.Socket do
  begin
    Memo1.Clear;
    ClientSocket1.Host := url;
    ClientSocket1.Active := True;
    // muy posiblemente este código no deba estar aca
    // sino en el evento onConnect para que te responda con un solo click
    SendText('GET / HTTP/1.0'+#13#10);
    SendText(''+#13#10);
  end;
end;
procedure TForm1.Button1Click(Sender: TObject);
//var url: string;
begin
//  url:= Edit1.Text;
//PeticionWeb(url);
// reemplazamos todo por:
  PeticionWeb(Edit1.Text);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
  Close;
end;
procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
begin
  memo1.Lines.Add(ClientSocket1.Socket.ReceiveText);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ClientSocket1.Free;
end;
end.
__________________
[Crandel]
Responder Con Cita