利用delphi开发的软件 想实现客户端和服务器之间的小文件传输用什么控件比较好 用的sql数据库 用什么控件

利用delphi开发的软件想实现客户端和服务器之间的小文件传输用什么控件比较好用的sql数据库用什么控件好一点?最好能详细讲解一下控件的使用方法和设置~~跪求各位大神!!... 利用delphi开发的软件 想实现客户端和服务器之间的小文件传输用什么控件比较好 用的sql数据库 用什么控件好一点? 最好能详细讲解一下控件的使用方法和设置~~跪求各位大神!!~~ 展开
 我来答
匿名用户
2013-05-12
展开全部
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;
type
TCon = record
FileName : String;
TotalSize : Integer;
Status : Integer;
end;
PCON = ^TCON;
TForm1 = class(TForm)
SS: TServerSocket;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure SSClientConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure SSClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
SS.Port := 9000;
SS.Active := True;
end;
procedure TForm1.SSClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
var c : pcon;
begin
c :=new(pcon);
c.FileName := '';
c.TotalSize := 0
c.Status := 0;
Socket.Data := c;
Socket.SendText('已经连接,请输入UPLOAD FILENAME SIZE'#13#10);
end;
procedure TForm1.SSClientRead(Sender: TObject; Socket: TCustomWinSocket);
var C : PCON;
cmd:String;
Buffer : pointer;
nRetr : integer;
fs : TFileStream;
const bufferSize = 1024
begin
C:= Socket.Data
case c.Status of
0 :
begin
cmd := trim(Socket.ReceiveText)
if Pos('UPLOAD ',uppercase(cmd)) > 0 then
begin
c.FileName := trim(Copy(cmd,Pos(' ',cmd)+1,Length(cmd)));
c.TotalSize := StrToInt(Copy(c.FileName,Pos(' ',c.FileName)+1,Length(c.FileName)));
c.FileName := trim(Copy(c.FileName,1,Pos(' ',c.FileName)));
c.Status := 1;
Socket.Data := C;
Socket.SendText('you can send File !'#13#10);
end;
end;
1 : begin
GetMem(Buffer,BufferSize);
nRetr := Socket.ReceiveBuf(Buffer^,BufferSize);
if not FIleExists('c:\'+c.FileName) then
begin
fs :=TFileStream.Create('c:\'+c.FileName,fmCreate or fmShareDenyNone);
fs.Seek(0,soFromBeginning);
end
else
begin
fs :=TFileStream.Create('c:\'+c.FileName,fmOpenWrite or fmShareDenyNone);
fs.Seek(0,soFromEnd);
end;
fs.WriteBuffer(Buffer^,nRetr);
fs.Destroy;
FreeMem(Buffer);
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Form2.Show;
end;
end.

--------------------------------------------------------------------------------
来自:唐晓锋 时间:99-11-30 01:17:19 ID:162654
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ScktComp;
type
TForm2 = class(TForm)
CS: TClientSocket;
OpenDialog1: TOpenDialog;
Memo1: TMemo;
Button1: TButton;
Edit1: TEdit;
Button2: TButton;
SendCommand: TButton;
Label1: TLabel;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure SendCommandClick(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure CSRead(Sender: TObject; Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
function GetFileSize(const FileName: string):integer;
var f : TFileStream;
begin
f := TFileStream.Create(FileName,fmOpenRead or fmShareDenyNone);
Result :=f.Size;
F.Free;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
with OpenDialog1 do
begin
Execute;
if FileName <> '' then
begin
Edit1.Text := 'UPLOAD '+ ExtractFileName(FileName) +' '+Inttostr(GetFileSize(FileName));
Label1.Caption := FileName;
cs.Socket.SendText(edit1.Text);
end;
end;
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
CS.Active := True;
end;
procedure TForm2.SendCommandClick(Sender: TObject);
var fs : TFileStream;
Buf : pointer;
begin
//CS.Socket.SendText(Edit1.Text+#13#10);
//Memo1.Lines.Add();
fs := TFileStream.Create(Label1.Caption ,fmOpenRead or fmShareDenyNone);
GetMem(Buf,fs.Size);
fs.Seek(0,soFromBeginning);
fs.ReadBuffer(Buf^,fs.Size);
memo1.Lines.Add('has send : '+inttostr(Cs.Socket.SendBuf(Buf^,fs.Size)));
end;
procedure TForm2.Button3Click(Sender: TObject);
begin
cs.Close;
end;
procedure TForm2.CSRead(Sender: TObject; Socket: TCustomWinSocket);
begin
Memo1.Lines.add(socket.receiveText);
end;
end.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
darlingks
2013-05-14 · TA获得超过222个赞
知道小有建树答主
回答量:638
采纳率:75%
帮助的人:173万
展开全部
TClientSocket TServerSocker 这2个控件 Internet面板中 没安装过的话 需要安装:
Component -> Install Packages -> Add ->选择你的Delphi安装目录中Bin文件夹下的dclsockets70.bpl
OK 安装即可

任何格式的文件传输, 都可以用流形式来传输[TStream类]。
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
crazy_boom
2013-05-13
知道答主
回答量:26
采纳率:0%
帮助的人:4.4万
展开全部
买一本delphi 开发大全 仔细阅读
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式