Advanced Delphi Systems- İnternet Sayfası

Yazdığınız makaleleri ve üyelerimizin işine yarayacağını düşündüğünüz kodlarınızı gönderebilirsiniz. Bu foruma soru sormayın!
Cevapla
Kullanıcı avatarı
Asri
Kıdemli Üye
Mesajlar: 767
Kayıt: 16 Eyl 2003 09:54
Konum: istanbul

Advanced Delphi Systems- İnternet Sayfası

Mesaj gönderen Asri »

Aşağıdaki unit'i unit1'de uses olarak ekleyip bu unit içindeki procedure ve function'ları kullanbilirsiniz.

Bu unit program internet sayfa işleminde kullanılır.

Kod: Tümünü seç

unit Ads_intnet_NM;
{Richard Maley
 Advanced Delphi Systems
 12613 Maidens Bower Drive
 Potomac, MD 20854
 301-840-1554
 maley@compuserve.com
 maley@advdelphisys.com
 maley@cpcug.org
 rmaley@fenix2.dol-esa.gov}

{
All of these utilities assume you have the NetMasters FastNet
internet components.  The FastNet components can be purchased
from NetMasters at http://www.netmastersllc.com.
}

interface
Uses SysUtils, NMHttp, ExtCtrls, Buttons, Classes;

{!~
NMHTTP_GETURLTOFILE

This utility assumes you have the NetMasters FastNet
internet components.  The FastNet components can be purchased
from NetMasters at http://www.netmastersllc.com.

This utility copies a URL to file.

}
Function NMHttp_GetURLToFile(
  NMHttp       : TNMHttp;
  SourceURL    : String;
  DestFile     : String;
  Button_Stop  : TSpeedButton
  ): Boolean;

{!~
NMHTTP_ISURL

This utility assumes you have the NetMasters FastNet
internet components.  The FastNet components can be purchased
from NetMasters at http://www.netmastersllc.com.

This utility tests the existance of a URL.  If the URL exists
True is returned, otherwise False.

}
Function NMHttp_IsUrl(NMHttp: TNMHttp; URLString: String): Boolean;

Procedure NMHttp_OnConnect(MsgPanel : TPanel);
Procedure NMHttp_OnConnectionFailed(MsgPanel: TPanel);
Procedure NMHttp_OnDisconnect(MsgPanel : TPanel);
Procedure NMHttp_OnFailure(MsgPanel: TPanel;Cmd: CmdType);
Procedure NMHttp_OnHostResolved(MsgPanel : TPanel);
Procedure NMHttp_OnPacketRecvd(NMHttp: TNMHttp;MsgPanel: TPanel);
Procedure NMHttp_OnPacketSent(NMHttp: TNMHttp;MsgPanel: TPanel);
Procedure NMHttp_OnStatus(NMHttp: TNMHttp;MsgPanel: TPanel;Status: String);
Procedure NMHttp_OnSuccess(MsgPanel: TPanel;Cmd: CmdType);

{!~
NMHttp_PostURLToFile

This utility assumes you have the NetMasters FastNet
internet components.  The FastNet components can be purchased
from NetMasters at http://www.netmastersllc.com.

This utility copies a URL to file using http post.

}
Function NMHttp_PostURLToFile(
  NMHttp       : TNMHttp;
  SourceURL    : String;
  Parameters   : String;
  DestFile     : String;
  Button_Stop  : TSpeedButton
  ): Boolean;



implementation

Function NMHttp_URLToFileDetail(
  NMHttp       : TNMHttp;
  SourceURL    : String;
  Parameters   : String;
  DestFile     : String;
  Button_Stop  : TSpeedButton
  ): Boolean;
Var
  BodyFile_SL             : TStringList;
  BodyFile                : String;
begin
  Try
    Button_Stop.Enabled   := True;
    BodyFile              := DestFile;
    NMHttp.InputFileMode  := False;
    NMHttp.OutputFileMode := False;
    NMHttp.Header         := 'Header.Txt';
    NMHttp.Body           := BodyFile;
    NMHttp.ReportLevel    := 2;
    With NMHttp.HeaderInfo do
    Begin
      Cookie           := '';
      LocalMailAddress := '';
      LocalProgram     := '';
      Referer          := '';
      UserID           := '';
      Password         := '';
    End;

    If (Parameters = '') Then
    Begin
      NMHttp.Get(SourceURL);
    End
    Else
    Begin
      NMHttp.Post(SourceURL,Parameters);
    End;

    BodyFile_SL := TStringList.Create();
    Try
      BodyFile_SL.Clear;
      BodyFile_SL.Add(NMHttp.Body);
      BodyFile_SL.SaveToFile(BodyFile);
    Finally
      BodyFile_SL.Free;
    End;
    Result := True;
  Except
    Result := False;
  End;
  Button_Stop.Enabled := False;
end;

{!~
NMHTTP_GETURLTOFILE

This utility assumes you have the NetMasters FastNet
internet components.  The FastNet components can be purchased
from NetMasters at http://www.netmastersllc.com.

This utility copies a URL to file.

}
Function NMHttp_GetURLToFile(
  NMHttp       : TNMHttp;
  SourceURL    : String;
  DestFile     : String;
  Button_Stop  : TSpeedButton
  ): Boolean;
begin
  Result :=
    NMHttp_URLToFileDetail(
      NMHttp,
      SourceURL,
      '',
      DestFile,
      Button_Stop
      );
end;

{!~
NMHttp_PostURLToFile

This utility assumes you have the NetMasters FastNet
internet components.  The FastNet components can be purchased
from NetMasters at http://www.netmastersllc.com.

This utility copies a URL to file using http post.

}
Function NMHttp_PostURLToFile(
  NMHttp       : TNMHttp;
  SourceURL    : String;
  Parameters   : String;
  DestFile     : String;
  Button_Stop  : TSpeedButton
  ): Boolean;
begin
  Result :=
    NMHttp_URLToFileDetail(
      NMHttp,
      SourceURL,
      Parameters,
      DestFile,
      Button_Stop
      );
end;

Procedure NMHttp_OnConnect(MsgPanel : TPanel);
Begin
  If MsgPanel <> nil Then
  Begin
    MsgPanel.Caption := 'Connected';
    MsgPanel.Refresh;
  End;
End;

Procedure NMHttp_OnDisconnect(MsgPanel : TPanel);
Begin
  If MsgPanel <> nil Then
  Begin
    MsgPanel.Caption := 'Disconnected';
    MsgPanel.Refresh;
  End;
End;

Procedure NMHttp_OnFailure(MsgPanel: TPanel;Cmd: CmdType);
Begin
  If MsgPanel <> nil Then
  Begin
    Case Cmd Of
      CmdGET:     MsgPanel.Caption := 'Get Failed';
      CmdOPTIONS: MsgPanel.Caption := 'Options Failed';
      CmdHEAD:    MsgPanel.Caption := 'Head Failed';
      CmdPOST:    MsgPanel.Caption := 'Post Failed';
      CmdPUT:     MsgPanel.Caption := 'Put Failed';
      CmdPATCH:   MsgPanel.Caption := 'Patch Failed';
      CmdCOPY:    MsgPanel.Caption := 'Copy Failed';
      CmdMOVE:    MsgPanel.Caption := 'Move Failed';
      CmdDELETE:  MsgPanel.Caption := 'Delete Failed';
      CmdLINK:    MsgPanel.Caption := 'Link Failed';
      CmdUNLINK:  MsgPanel.Caption := 'UnLink Failed';
      CmdTRACE:   MsgPanel.Caption := 'Trace Failed';
      CmdWRAPPED: MsgPanel.Caption := 'Wrapped Failed';
    End;
    MsgPanel.Refresh;
  End;
End;

Procedure NMHttp_OnHostResolved(MsgPanel : TPanel);
Begin
  If MsgPanel <> nil Then
  Begin
    MsgPanel.Caption := 'Host Resolved';
    MsgPanel.Refresh;
  End;
End;

Procedure NMHttp_OnPacketRecvd(
  NMHttp   : TNMHttp;
  MsgPanel : TPanel);
Var
  Tot : Integer;
Begin
  Tot := NMHttp.BytesTotal;
  If Tot = 0 Then
  Begin
    MsgPanel.Caption :=
      IntToStr(NMHttp.BytesRecvd)+
      ' bytes retrieved';
  End
  Else
  Begin
    MsgPanel.Caption :=
      IntToStr(NMHttp.BytesRecvd)+
      ' of '+
      IntToStr(NMHttp.BytesTotal)+' retrieved';
  End;
  MsgPanel.Refresh;
End;

Procedure NMHttp_OnPacketSent(NMHttp: TNMHttp;MsgPanel: TPanel);
Begin
  If MsgPanel <> nil Then
  Begin
    MsgPanel.Caption :=
      IntToStr(NMHttp.BytesSent)+
      ' of '+
      IntToStr(NMHttp.BytesTotal)+
      ' sent';
    MsgPanel.Refresh;
  End;
End;

Procedure NMHttp_OnStatus(NMHttp: TNMHttp;MsgPanel: TPanel;Status: String);
Begin
  If MsgPanel <> nil Then
  Begin
    MsgPanel.Caption := Status;
    If NMHttp.ReplyNumber = 404 Then
      MsgPanel.Caption := 'Object Not Found';
    MsgPanel.Refresh;
  End;
End;

Procedure NMHttp_OnSuccess(MsgPanel: TPanel;Cmd: CmdType);
Begin
  If MsgPanel <> nil Then
  Begin
    Case Cmd Of
      CmdGET:     MsgPanel.Caption := 'Get Succeeded';
      CmdOPTIONS: MsgPanel.Caption := 'Options Succeeded';
      CmdHEAD:    MsgPanel.Caption := 'Head Succeeded';
      CmdPOST:    MsgPanel.Caption := 'Post Succeeded';
      CmdPUT:     MsgPanel.Caption := 'Put Succeeded';
      CmdPATCH:   MsgPanel.Caption := 'Patch Succeeded';
      CmdCOPY:    MsgPanel.Caption := 'Copy Succeeded';
      CmdMOVE:    MsgPanel.Caption := 'Move Succeeded';
      CmdDELETE:  MsgPanel.Caption := 'Delete Succeeded';
      CmdLINK:    MsgPanel.Caption := 'Link Succeeded';
      CmdUNLINK:  MsgPanel.Caption := 'UnLink Succeeded';
      CmdTRACE:   MsgPanel.Caption := 'Trace Succeeded';
      CmdWRAPPED: MsgPanel.Caption := 'Wrapped Succeeded';
    End;
    MsgPanel.Refresh;
  End;
End;

Procedure NMHttp_OnConnectionFailed(MsgPanel: TPanel);
Begin
  If MsgPanel <> nil Then
  Begin
    MsgPanel.Caption := 'Connection Failed';
    MsgPanel.Refresh;
  End;
End;

{!~
NMHTTP_ISURL

This utility assumes you have the NetMasters FastNet
internet components.  The FastNet components can be purchased
from NetMasters at http://www.netmastersllc.com.

This utility tests the existance of a URL.  If the URL exists
True is returned, otherwise False.

}
Function NMHttp_IsUrl(NMHttp: TNMHttp; URLString: String): Boolean;
Begin
  Try
    If FileExists(URLString) Then
    Begin
      Result := True;
      Exit;
    End;
  Except
  End;
  Try
    NMHttp.Head(URLString);
    Result := True;
  Except
    Result := False;
  End;
End;

End.
Öğrenmek ve öğretmek, akıntıya karşı yüzmek gibidir ilerleyemediğiniz taktirde gerilersiniz.
Cevapla