我写一程序,涉及到SQL数据库.我用写成这样:  DBGrid 不断的读取数据库纪录,指针不断向下跳.每跳到下一条纪录,就完成把本地的E盘的照片传到网络上的共享文件下.但是,我的问题是:::当网络断开的时候,我想让我的程序停止工作.也就是那个DBGrid的指针不向下继续读数据.只是停在那不动,当程序检测到计算机连上网络的时候.此时DBGrid继续向下读取数据工作...就是如此,关键是程序停止,以及检测网络状态...------------------------------------小弟很急,,,,在线等答案!!!!分不够开帖...

解决方案 »

  1.   

    你先找一个完成简单PING功能的代码,在你的程序复制文件之前,PING一下网络,如果通的话就继续复制文件,如果不通,则停止,并给出提示。
    PING能功的代码很多,你随便SEARCH一下就有了
      

  2.   

    你先PING一下所连接的那台计算机
    具体代码如下
    type
      PIPOptionInformation = ^TIPOptionInformation;
      TIPOptionInformation = packed record
        TTL: Byte;
        TOS: Byte;
        Flags: Byte;
        OptionsSize: Byte;
        OptionsData: PChar;
      end;
      type PIcmpEchoReply = ^TIcmpEchoReply;
      TIcmpEchoReply = packed record
        Address: DWORD;
        Status: DWORD;
        RTT: DWORD;
        DataSize:Word;
        Reserved: Word;
        Data: Pointer;
        Options: TIPOptionInformation;
      end;
      TIcmpCreateFile = function: THandle; stdcall;
      TIcmpCloseHandle = function(IcmpHandle: THandle): Boolean; stdcall;
      TIcmpSendEcho = function(IcmpHandle:THandle;
                               DestinationAddress:DWORD;
                               RequestData: Pointer;
                               RequestSize: Word;
                               RequestOptions: PIPOptionInformation;
                               ReplyBuffer: Pointer;
                               ReplySize: DWord;
                               Timeout: DWord): DWord; stdcall;
      private
        { Private declarations }
      hICMP: THANDLE;
      IcmpCreateFile : TIcmpCreateFile;
      IcmpCloseHandle:TIcmpCloseHandle;
      IcmpSendEcho: TIcmpSendEcho;
      line:integer;  public
        { Public declarations }
      hICMPdll: HMODULE;
      end;var
      Form1: TForm1;
    implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
    begin
      hICMPdll := LoadLibrary('icmp.dll');
      @ICMPCreateFile:= GetProcAddress(hICMPdll, 'IcmpCreateFile');
      @IcmpCloseHandle := GetProcAddress(hICMPdll, 'IcmpCloseHandle');
      @IcmpSendEcho := GetProcAddress(hICMPdll, 'IcmpSendEcho');
      hICMP := IcmpCreateFile;
      end;procedure TForm1.Button1Click(Sender: TObject);
    var
      IPOpt:TIPOptionInformation;
      FIPAddress:DWORD;
      pReqData,pRevData:PChar;
      pIPE:PIcmpEchoReply;
      FSize: DWORD;
      MyString:string;
      FTimeOut:DWORD;
      BufferSize:DWORD;
    begin
      if Edit1.Text <> '' then
      begin
        FIPAddress:=inet_addr(PChar(‘192.168.0.1’));//你所PING的IP地址
        if Fipaddress=INADDR_NONE then
         Messagebox(self.handle,'地址无效','Ping32',64)
        else
        begin
            FSize:=80;
            BufferSize:=SizeOf(TICMPEchoReply)+FSize;
            GetMem(pRevData,FSize);
            GetMem(pIPE,BufferSize);
            FillChar(pIPE^, SizeOf(pIPE^), 0);
            pIPE^.Data := pRevData;
            MyString := 'Argen Ping32 Sending Message.';
            pReqData := PChar(MyString);
            FillChar(IPOpt, Sizeof(IPOpt), 0);
            IPOpt.TTL:= 64;
            FTimeOut :=500;
            IcmpSendEcho(hICMP, FIPAddress, pReqData, Length(MyString),@IPOpt, pIPE,
            BufferSize, FTimeOut);
            try
              try
      
              if pReqData^ = pIPE^.Options.OptionsData^ then
              Messagebox(self.handle,'目标到','Ping32',64)
                 except
                Messagebox(self.handle,'目标不可到','Ping32',64)
              end;
            finally
              FreeMem(pRevData);
              FreeMem(pIPE);
            end;
        end;
      end;
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      icmpclosehandle(hicmp);
      freelibrary(hicmpdll);
    end;end.