IdTCPClient传输文件出错

lupingyang 2010-04-30 12:25:49
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, ComCtrls;

type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
IdTCPClient1: TIdTCPClient;
Button1: TButton;
edtFileName: TEdit;
edtAddress: TEdit;
Button2: TButton;
ProgressBar1: TProgressBar;
StatusBar1: TStatusBar;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Execute;
edtFileName.Text:=OpenDialog1.FileName
end;

procedure TForm1.Button2Click(Sender: TObject);
var
iFileHandle:integer;
iFileLen,cnt:integer;
buf:array[0..4096] of byte;
begin
if (edtAddress.Text<>'')and (edtFileName.Text<>'') then
begin
IdTCPClient1.Host:=edtAddress.Text;
IdTCPClient1.Port:=9925;
try
IdTCPClient1.Connect(5000);
except
StatusBar1.Panels[0].Text:='连接接受方失败!';
exit;
end;
if IdTCPClient1.Connected then
begin
iFileHandle:=FileOpen(edtFileName.Text,fmOpenRead);
iFileLen:=FileSeek(iFileHandle,0,2);
FileSeek(iFileHandle,0,0);
ProgressBar1.Max:=iFileLen;
ProgressBar1.Position := 0;
IdTCPClient1.WriteLn(ExtractFileName(edtFileName.Text)+'|'+IntToStr(iFileLen));
while true do
begin
Application.ProcessMessages;
cnt:=FileRead(iFileHandle,buf,4096);
IdTCPClient1.WriteBuffer(buf,cnt);
IdTCPClient1.WriteInteger(cnt);
ProgressBar1.Position:=ProgressBar1.Position + cnt;
StatusBar1.Panels[0].Text:='正在传送文件...';
if cnt<4096 then
break;
end;
FileClose(iFileHandle);
Label2.Caption:='文件传送完成!';
StatusBar1.Panels[0].Text:='文件传送完成!';
end;
end
else
ShowMessage('请选择要传送的文件和或接受方地址');

end;

end.



错误:list index out of bounds(0)
...全文
128 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
李_军 2010-04-30
  • 打赏
  • 举报
回复
单步调试下,检查是不是StatusBar1.Panels这个控件你根本没增加Panel
内容概要:本文围绕超导磁能储存系统(SMES)的建模与仿真展开,基于Simulink平台构建系统级动态仿真模型,涵盖超导线圈、功率转换系统(PCS)以及核心控制策略等关键模块。研究重点在于分析SMES在电网中实现快速能量存储与释放的能力,验证其在提升电力系统稳定性、抑制功率波动方面的有效性,尤其针对新能源发电带来的间歇性与波动性问题提供了有效的解决方案。通过仿真手段深入探讨系统的动态响应特性,为优化控制算法的设计与应用提供可靠的技术支撑。; 适合人群:适用于具备电力系统、自动控制理论或能源存储技术背景,熟悉Simulink仿真环境的科研人员、工程技术人员及研究生;同时适合有志于开展新型储能技术仿真研究的高年级本科生参考学习。; 使用场景及目标:①深入理解超导磁能储存系统的基本结构、工作原理及其在电力系统中的应用场景;②掌握在Simulink中搭建复杂电力电子与控制系统联合仿真模型的方法;③研究SMES在电网调频、电压支撑、瞬时功率补偿等典型工况下的动态性能表现;④为后续先进控制策略(如PID、模糊控制、现代控制理论等)的优化设计与验证提供仿真试验平台。; 阅读建议:建议读者结合文中模型逐步动手搭建仿真系统,重点关注各功能模块的参数设置与信号接口匹配,配合具体案例进行仿真调试,深入理解控制逻辑与系统动态行为之间的内在联系,并可进一步拓展至与其他储能形式(如锂电池、飞轮储能)的性能对比研究,以深化对不同类型储能技术特点的认知。

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧