经常拜读各位大侠的文章,今天也自己发表一片.请大家批评指正.
文件发送端源代码
.h文件
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ScktComp.hpp>
#include <Dialogs.hpp>
#include <Buttons.hpp>
#include <ComCtrls.hpp>
#include <Menus.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TOpenDialog *OpenDialog1;
TSpeedButton *SpeedButton1;
TComboBox *ComboBox1;
TSpeedButton *SpeedButton2;
TListView *ListView1;
TLabel *Label1;
TPopupMenu *PopupMenu1;
TMenuItem *N1;
TClientSocket *ClientSocket1;
TSpeedButton *SpeedButton3;
TPanel *Panel1;
TStatusBar *StatusBar1;
void __fastcall SpeedButton1Click(TObject *Sender);
void __fastcall SpeedButton2Click(TObject *Sender);
void __fastcall N1Click(TObject *Sender);
void __fastcall ClientSocket1Read(TObject *Sender,
TCustomWinSocket *Socket);
void __fastcall SpeedButton3Click(TObject *Sender);
void __fastcall ClientSocket1Error(TObject *Sender,
TCustomWinSocket *Socket, TErrorEvent ErrorEvent,
int &ErrorCode);
private: // User declarations
void __fastcall DisplayHint(TObject *Sender);
public: // User declarations
int port;
int FileCount;
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <ScktComp.hpp>
//---------------------------------------------------------------------------
class TSend : public TThread
{
private:
TClientSocket *p;
AnsiString filename;
protected:
void __fastcall Execute();
public:
int index;
__fastcall TSend(bool CreateSuspended,TClientSocket *p1,AnsiString file);
};
//---------------------------------------------------------------------------
#endif
.cpp文件
#include <vcl.h>
#pragma hdrstop
#include <vcl/dstring.h>
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString name;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Application->OnHint = DisplayHint;
FileCount=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
if(OpenDialog1->Execute())
name=OpenDialog1->FileName;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SpeedButton2Click(TObject