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

📄 newsrdr1.pas

📁 文件名称:新曦 我的资源 搜索软件 源程序(Borland Delphi 7)说明
💻 PAS
📖 第 1 页 / 共 2 页
字号:
        Display('Unknown request type.');
    end;

    { If any stream where used, destroy it }
    if Assigned(FDataStream) then begin
        FDataStream.Free;
        FDataStream := nil;
    end;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This event handler is called by TNntpCli when it has received data and    }
{ don't know what to do with it. It should normally not occur !             }
procedure TNNTPForm.NntpCli1DataAvailable(Sender: TObject; Error: Word);
begin
    Display('Data: ' + NntpCli1.LastResponse);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This event handler is called by TNntpCli component just before the        }
{ component will begin receiving a message. It's a good place to open a     }
{ file or start a progress bar.                                             }
procedure TNNTPForm.NntpCli1MessageBegin(Sender: TObject);
begin
    Display('Message begin');
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This event handler is called by TNntpCli component for each line of an    }
{ incomming message. Header line as well as body lines are comming here.    }
{ It's a good place to write to a file or update screen or progress bar.    }
{ It's also the place to intercept header lines.                            }
procedure TNNTPForm.NntpCli1MessageLine(Sender: TObject);
var
    NewsGroupName   : String;
    LastArticle     : Integer;
    FirstArticle    : Integer;
    PostingFlag     : Char;
begin
    Display('Line: ' + NntpCli1.LastResponse);
    ParseListLine(NntpCli1.LastResponse,
                  NewsGroupName,
                  LastArticle,
                  FirstArticle,
                  PostingFlag);
    { It the place to do something with NewsGroupName, LastArticle, }
    { FirstArticle and PostingFlag                                  }
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This event handler is called by TNntpCli component when a message has     }
{ been received completely. It's a good place to close a file, delete the   }
{ progress bar and alert user.                                              }
procedure TNNTPForm.NntpCli1MessageEnd(Sender: TObject);
begin
    Display('Message End');
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ This function is called internally to create a TFileStream if any file    }
{ name is specified in the FileEdit box. If the edit box is blank, nil is   }
{ returned. The TFileStream will be supplyed to the comoponent for every    }
{ command which can take a TStream to store data such as ArticleByNum.      }
{ The stream is destroyed in the OnRequestDone event handler.               }
function TNNTPForm.GetStream : TStream;
begin
    { Delete the previous stream if not already done }
    if Assigned(FDataStream) then begin
        FDataStream.Free;
        FDataStream := nil;
    end;

    if Trim(FileEdit.Text) = '' then
        FDataStream := nil
    else begin
        { Try to open the file stream. Trap errors. }
        try
            FDataStream := TFileStream.Create(Trim(FileEdit.Text), fmCreate);
        except
            on E:Exception do begin
                { Display an error message in our TMemo }
                Display(E.Message);
                FDataStream := nil;
                raise;  { Show the exception box }
            end;
        end;
    end;
    Result := FDataStream;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.ConnectButtonClick(Sender: TObject);
begin
    DisplayMemo.Clear;
    ConnectButton.Enabled := FALSE;
    NntpCli1.Host         := ServerEdit.Text;
    NntpCli1.Connect;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.AbortButtonClick(Sender: TObject);
begin
    NntpCli1.Abort;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.QuitButtonClick(Sender: TObject);
begin
    NntpCli1.Quit;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.GroupButtonClick(Sender: TObject);
begin
    NntpCli1.Group(GroupEdit.Text);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.NextButtonClick(Sender: TObject);
begin
    NntpCli1.Next;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.LastButtonClick(Sender: TObject);
begin
    NntpCli1.Last;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.ArticleByIDButtonClick(Sender: TObject);
begin
    NntpCli1.ArticleByID(ArticleIDEdit.Text, GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.ArticleByNumberButtonClick(Sender: TObject);
begin
    NntpCli1.ArticleByNumber(StrToInt(ArticleNumEdit.Text), GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.HeadByIDButtonClick(Sender: TObject);
begin
    NntpCli1.HeadByID(ArticleIDEdit.Text, GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.HeadByNumberButtonClick(Sender: TObject);
begin
    NntpCli1.HeadByNumber(StrToInt(ArticleNumEdit.Text), GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.BodyByIDButtonClick(Sender: TObject);
begin
    NntpCli1.BodyByID(ArticleIDEdit.Text, GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.BodyByNumberButtonClick(Sender: TObject);
begin
    NntpCli1.BodyByNumber(StrToInt(ArticleNumEdit.Text), GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.StatByIDButtonClick(Sender: TObject);
begin
    NntpCli1.StatByID(ArticleIDEdit.Text);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.StatByNumberButtonClick(Sender: TObject);
begin
    NntpCli1.StatByNumber(StrToInt(ArticleNumEdit.Text));
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.ListButtonClick(Sender: TObject);
begin
    if Application.MessageBox('This could take a VERY long time, proceed ? ',
                              'Warning', MB_YESNO) <> ID_YES then
        Exit;
    NntpCli1.List(GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.NewGroupsButtonClick(Sender: TObject);
begin
    NntpCli1.NewGroups(Now - 10, FALSE, '', GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.NewNewsButtonClick(Sender: TObject);
begin
    NntpCli1.NewNews(Now - 1, FALSE, GroupEdit.Text, '', GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.HelpButtonClick(Sender: TObject);
begin
    NntpCli1.Help(GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNntpForm.LineToStream(Buf : String);
begin
    Display('Line: ' + Buf);
    Buf := Buf + #13#10;
    FDataStream.WriteBuffer(Buf[1], Length(Buf));
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
{ Posting a message require to build the message, including his header.     }
{ Here we use a TMemoryStream to create a message on the fly. Normally we   }
{ should use a TFileStream to get the message from a file where it has      }
{ been written by some user interface.                                      }
procedure TNNTPForm.PostButtonClick(Sender: TObject);
begin
    { Delete the stream if not already done }
    if Assigned(FDataStream) then begin
        FDataStream.Free;
        FDataStream := nil;
    end;

    { Create a new stream in memory }
    FDataStream := TMemoryStream.Create;

    { Write the message header }
    LineToStream('From: ' + UserEdit.Text);
    LineToStream('Newsgroups: ' + GroupEdit.Text);
    LineToStream('Subject: Internet Components Suite (ICS)');
    LineToStream('Organization: None');
    LineToStream('X-Newsreader: NNTP component ' +
                 '(http://www.overbyte.be)');

    { End of header is a blank line }
    LineToStream('');

    { Write the message body }
    LineToStream('');
    LineToStream('The Internet Component Suite is a set of native');
    LineToStream('components for Borland Delphi (all versions,');
    LineToStream('including 16 bits) and Borland C++ Builder. The');
    LineToStream('major TCP/IP protocols are supported for building');
    LineToStream('client/server, intranet or Internet applications.');
    LineToStream('');
    LineToStream('TCP, UDP, TELNET, FTP, SMTP, POP3, PING, FINGER, HTTP,');
    LineToStream('NNTP and more. Each component has samples writen');
    LineToStream('in Delphi and in C++ Builder. Several client/server');
    LineToStream('applications, including an event-driven and a');
    LineToStream('multi-threaded server, a complete FTP client and');
    LineToStream('TELNET client with ansi emulation are provided.');
    LineToStream('Full source code provided for everything.');
    LineToStream('');
    LineToStream('The Internet Component Suite is freeware, royalty');
    LineToStream('free and support is done using a mailing list.');
    LineToStream('Visit our website and download now from');
    LineToStream('http://www.overbyte.be');

    { Set stream pointer to beginning of stream because TNntpCli will post }
    { from the current position                                            }
    FDataStream.Seek(0, soFromBeginning	);

    { Ask the component to post the stream. The posting occurs in the      }
    { background ! We will receive the OnRequestDone event when done.      }
    { It's in this event handler that the stream must be destroyed         }
    NntpCli1.Post(FDataStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.XOverButtonClick(Sender: TObject);
begin
    NntpCli1.XOver(ArticleNumEdit.Text, GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.OverViewFmtButtonClick(Sender: TObject);
begin
    NntpCli1.ListOverViewFmt(GetStream);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.DateButtonClick(Sender: TObject);
begin
    NntpCli1.Date;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.AuthenticateButtonClick(Sender: TObject);
begin
    NntpCli1.UserName := UserNameEdit.Text;
    NntpCli1.Password := PasswordEdit.Text;
    NntpCli1.Authenticate;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.ModeReaderButtonClick(Sender: TObject);
begin
    NntpCli1.ModeReader;
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.XHdrButtonClick(Sender: TObject);
begin
    NntpCli1.XHdr(GetStream, 'subject', ArticleNumEdit.Text);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.NntpCli1XHdrBegin(Sender: TObject);
begin
    Display('XHdr begin');
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.NntpCli1XHdrEnd(Sender: TObject);
begin
    Display('Xhdr End');
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}
procedure TNNTPForm.NntpCli1XHdrLine(Sender: TObject);
begin
    Display('XHdr: ' + NntpCli1.LastResponse);
end;


{* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *}

end.

⌨️ 快捷键说明

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