请教应用NMUDP控件实现发送和接收数据出现的问题。感谢!
头文件SRData.h 如下:
//---------------------------------------------------------------------------
#ifndef SRDataH
#define SRDataH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <NMUDP.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
TEdit *Edit1;
TButton *Button1;
TButton *Button2;
TMemo *Memo1;
TStatusBar *StatusBar1;
TNMUDP *NMUDP1;
TEdit *Edit2;
TEdit *Edit3;
void __fastcall Button1Click(TObject *Sender);
void __fastcall Button2Click(TObject *Sender);
void __fastcall Memo1Change(TObject *Sender);
void __fastcall NMUDP1BufferInvalid(bool &handled,
_ARRAYOF char* Buff, const int Buff_Size, int &length);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
SRData.cpp文件如下:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "SRData.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (OpenDialog1->Execute())
{
Edit3->Text=OpenDialog1->Filename;
}
Memo1->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(Edit3->Text=="")
{
ShowMessage("Please select one file");
return;
}
NMUDP1->RemoteHost=Edit1->Text; //设计远程主机和端口号
NMUDP1->RemotePort=StrToInt(Edit2->Text);
NMUDP1->ReportLevel=Nmudp::Status_Basic;
const int ThreshHold=2048; //每次读取2048字节的数据
TFileStream *Strm=new TFileStream(Edit3->Text,fmOpenRead); //载入文件流
char *Buffer=new char[ThreshHold]; // 存放所读数据的缓冲区
int BuffSize=Strm->Size; // 文件大小
int Buffers=BuffSize/ThreshHold; //循环读取次数
for(int i=0;i<=Buffers;i++) //读取文件数据
{
if(BuffSize>2048)
{
Strm->Read(Buffer,ThreshHold);
NUMUDP1->SendBuffer(Buffer,ThreshHold,ThreshHold);
}
else
{
Strm->Read(Buffer,BuffSize);
NMUDP1->SendBuffer(Buffer,ThreshHold,ThreshHold);
BuffSize=ThreshHold;
ShowMessage("hehe");
}
delete[] Buffer;
delete Strm;
Memo1->Lines->Add("");
// 问题报错如下:
[c++Error] SRData.h (32):E2303 Type name expected
[c++Error] SRData.cpp(19):E2451 Undefined symbol 'OpenDialog1'
[c++Error] SRData.cpp(52):E2206 Illegal character '}' (0xa3fd)
[c++Error] SRData.cpp(64):E2089 Identifier 'NMUDP1DataSend' cannot have a type qualifier
[c++Error] SRData.cpp(71):E2206 Illegal character '}' (0xa3fd)
[c++Error] SRData.cpp(77):E2451 Undefined symbol 'TmpBuffer'
[c++Error] SRData.cpp(77):E2451 Undefined symbol 'NumberBytes'
[c++Error] SRData.cpp(80):E2252 'catch' expected