📄 newsrdr1.cpp
字号:
ParseListLine(NntpCli1->LastResponse,
NewsGroupName,
LastArticle,
FirstArticle,
PostingFlag);
// It is the place to do something with NewsGroupName, LastArticle,
// FirstArticle and PostingFlag
}
//---------------------------------------------------------------------------
// 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.
void __fastcall TNNTPForm::NntpCli1MessageEnd(TObject *Sender)
{
Display("Message 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.
Classes::TStream* __fastcall TNNTPForm::GetStream(void)
{
// Delete the previous stream if not already done
if (FDataStream) {
delete FDataStream;
FDataStream = NULL;
};
if (Trim(FileEdit->Text) == "")
FDataStream = NULL;
else {
// Try to open the file stream. Trap errors.
try {
FDataStream = new TFileStream(Trim(FileEdit->Text), fmCreate);
} __except(TRUE) {
// Display an error message in our TMemo
Display("Can't open " + FileEdit->Text);
FDataStream = NULL;
throw; // Show the exception box
}
}
return(FDataStream);
};
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::ConnectButtonClick(TObject *Sender)
{
DisplayMemo->Clear();
ConnectButton->Enabled = FALSE;
NntpCli1->Host = ServerEdit->Text;
NntpCli1->Connect();
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::AbortButtonClick(TObject *Sender)
{
NntpCli1->Abort();
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::QuitButtonClick(TObject *Sender)
{
NntpCli1->Quit();
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::GroupButtonClick(TObject *Sender)
{
NntpCli1->Group(GroupEdit->Text);
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::NextButtonClick(TObject *Sender)
{
NntpCli1->Next();
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::LastButtonClick(TObject *Sender)
{
NntpCli1->Last();
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::ArticleByIDButtonClick(TObject *Sender)
{
NntpCli1->ArticleByID(ArticleIDEdit->Text, GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::ArticleByNumberButtonClick(TObject *Sender)
{
NntpCli1->ArticleByNumber(StrToInt(ArticleNumEdit->Text), GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::HeadByIDButtonClick(TObject *Sender)
{
NntpCli1->HeadByID(ArticleIDEdit->Text, GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::HeadByNumberButtonClick(TObject *Sender)
{
NntpCli1->HeadByNumber(StrToInt(ArticleNumEdit->Text), GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::BodyByIDButtonClick(TObject *Sender)
{
NntpCli1->BodyByID(ArticleIDEdit->Text, GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::BodyByNumberButtonClick(TObject *Sender)
{
NntpCli1->BodyByNumber(StrToInt(ArticleNumEdit->Text), GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::StatByIDButtonClick(TObject *Sender)
{
NntpCli1->StatByID(ArticleIDEdit->Text);
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::StatByNumberButtonClick(TObject *Sender)
{
NntpCli1->StatByNumber(StrToInt(ArticleNumEdit->Text));
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::ListButtonClick(TObject *Sender)
{
if (Application->MessageBox("This could take a VERY long time, proceed ? ",
"Warning", MB_YESNO) != ID_YES)
return;
NntpCli1->List(GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::NewGroupsButtonClick(TObject *Sender)
{
NntpCli1->NewGroups(Now() - 10, FALSE, "", GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::NewNewsButtonClick(TObject *Sender)
{
NntpCli1->NewNews(Now() - 1, FALSE, GroupEdit->Text, "", GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::HelpButtonClick(TObject *Sender)
{
NntpCli1->Help(GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::LineToStream(AnsiString Buf)
{
Display("Line: " + Buf);
Buf = Buf + "\r\n";
FDataStream->WriteBuffer(Buf.c_str(), Buf.Length());
};
//---------------------------------------------------------------------------
// 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.
void __fastcall TNNTPForm::PostButtonClick(TObject *Sender)
{
// Delete the stream if not already done
if (FDataStream) {
delete FDataStream;
FDataStream = NULL;
}
// Create a new stream in memory
FDataStream = new TMemoryStream;
// Write the message header
LineToStream("From: " + UserEdit->Text);
LineToStream("Newsgroups: " + GroupEdit->Text);
LineToStream("Subject: Internet components (winsock)");
LineToStream("Organization: None");
LineToStream("X-Newsreader: NNTP component "
"(http://www.rtfm.be/fpiette/indexuk.htm)");
// 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.rtfm.be/fpiette/indexuk.htm");
// 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);
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::XOverButtonClick(TObject *Sender)
{
NntpCli1->XOver(ArticleNumEdit->Text, GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::OverViewFmtButtonClick(TObject *Sender)
{
NntpCli1->ListOverViewFmt(GetStream());
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::DateButtonClick(TObject *Sender)
{
NntpCli1->Date();
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::AuthenticateButtonClick(TObject *Sender)
{
NntpCli1->UserName = UserNameEdit->Text;
NntpCli1->PassWord = PasswordEdit->Text;
NntpCli1->Authenticate();
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::ModeReaderButtonClick(TObject *Sender)
{
NntpCli1->ModeReader();
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::XHdrButtonClick(TObject *Sender)
{
NntpCli1->XHdr(GetStream(), "subject", ArticleNumEdit->Text);
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::NntpCli1XHdrBegin(TObject *Sender)
{
Display("XHdr begin");
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::NntpCli1XHdrEnd(TObject *Sender)
{
Display("Xhdr End");
}
//---------------------------------------------------------------------------
void __fastcall TNNTPForm::NntpCli1XHdrLine(TObject *Sender)
{
Display("XHdr: " + NntpCli1->LastResponse);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -