请帮我看一下翻页数组要怎么设

oTianLong123456 2020-01-08 06:00:23

读取execl数据在5个标签显示,ediit编辑框中录入对应的数据,当最后一个录入完毕后,数据要更新,更新要怎么赋值,试了多种方式,最后思路都弄乱了,代码传上,帮改一下:

procedure TForm1.btn1Click(Sender: TObject);
var
xls:TXLSReadWriteII5;
n,i,j,y:Integer;
cour :array of Integer;
begin
XLS := TXLSReadWriteII5.Create(Self);
XLS.LoadFromFile(ExtractFilePath(paramstr(0)) + '..\data\数据.xlsx');
try
XLS.Clear;
xls.Read;
lbl1.Caption:=IntToStr(xls.Sheets[1].LastRow ); //总数
for j := 1 to StrToInt(lbledt1.Text) do //
begin
for i:=1 to 5 do
begin
(FindComponent('Lblsc'+inttostr(i)) as TLabel).Caption := xls.Sheets[1].AsString[i-1, 1]; //标签用数组读取
end;
edt1.MaxLength:=Length(lblsc1.Caption);edt2.MaxLength:=Length(lblsc2.Caption);edt3.MaxLength:=Length(lblsc3.Caption);
edt4.MaxLength:=Length(lblsc4.Caption);edt5.MaxLength:=Length(lblsc5.Caption); //设置输入区对应长度
// cour[y]:= j+1 ; ?这赋值有问题,不知要怎么弄
end
finally
XLS.Free;
end;
end;

procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
if ((Key>=#32) and (Key<#255)) and (not (((Key >= '0') and (Key <= '9')) or (Key = '.') or (Key = '-'))) then // 只能输入数字,小数点,负号
begin
key := #0;
end;
end;

procedure TForm1.edt1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Length(edt1.Text) >= Length(lblsc1.Caption)) then edt2.SetFocus;
end;
.........
procedure TForm1.edt5KeyPress(Sender: TObject; var Key: Char);
begin
if ((Key>=#32) and (Key<#255)) and (not (((Key >= '0') and (Key <= '9')) or (Key = '.') or (Key = '-'))) then // 只能输入数字,小数点,负号
begin
key := #0;
end;
end;

procedure TForm1.edt5KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Length(edt5.Text) >= Length(lblsc5.Caption)) then
begin
edt1.Text:='';
edt2.Text:='';
edt3.Text:='';
edt4.Text:='';
edt5.Text:='';
edt1.SetFocus
end;
end;
...全文
160 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
oTianLong123456 2020-01-13
  • 打赏
  • 举报
回复
谢谢,已经调试出来了,供其它人参考吧。
function XlsRandValue(const lblsc: TLabel; shetidx, p: Integer): string;
var
xls: TXLSReadWriteII5;
i: Integer;
begin
xls := TXLSReadWriteII5.Create(nil);
xls.LoadFromFile(ExtractFilePath(paramstr(0)) + '..\data\数据.xlsx');
try
xls.Clear;
xls.Read;
for i := 1 to 5 do
begin
TLabel(main.FindComponent('lblsc' + inttostr(i))).Caption := xls.Sheets[shetidx].AsString[i - 1, p];
end;

finally
xls.Free;
end;
end;
  • 打赏
  • 举报
回复
xxx.FindComponent只能查找xxx拥有的组件,也就是组件的Owner是xxx的那些组件,你可能需要指出范围,比如Form1.FindComponent
oTianLong123456 2020-01-12
  • 打赏
  • 举报
回复
看来还是思路错误,必须用流或者定义过程类函数才能解决,但在定义过程函数中又出错,请大神帮忙看一下: unction XlsRandValue(const lblsc: TLabel; sheetindex: integer;p:TVarRec): integer; var xls:TXLSReadWriteII5; i:Integer; begin XLS := TXLSReadWriteII5.Create(nil); XLS.LoadFromFile(ExtractFilePath(paramstr(0)) + '..\data\数据.xlsx'); try XLS.Clear; xls.Read; try for i:=1 to 5 do begin (FindComponent('Lblsc'+inttostr(i)) as TLabel).Caption := xls.Sheets[1].AsString[i-1, p]; //标签用数组读取 end; finally Result := False; end; finally XLS.Free; end; if Assigned(XLS) then begin XLS.Destroy; end; end; 为什么这个不能用(FindComponent('Lblsc'+inttostr(i)) as TLabel).Caption := xls.Sheets[1].AsString[i-1, p];
oTianLong123456 2020-01-10
  • 打赏
  • 举报
回复
@早打大打打核战争,弄了一个星期也没弄出来,能否帮我改一下
  • 打赏
  • 举报
回复
数组下标越界,显然你这里List.Strings[j]的j超出了0..List.Count - 1范围
oTianLong123456 2020-01-09
  • 打赏
  • 举报
回复
能否创建个标签二维数组来实现
oTianLong123456 2020-01-09
  • 打赏
  • 举报
回复
用TStringList 类改为List.Strings[j]:=(FindComponent('Lblsc'+inttostr(i)) as TLabel).Caption;也会报错,,不知怎么弄请大神帮忙,用线程或指针就不会弄了

16,742

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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