我必须动态创建编辑框,我正在使用循环(循环变量 j)创建它。成功创建了5个组件,但是在第6个组件中,数组显示为nil(在调试过程中),即实际上没有创建任何内容。再次成功创建了第 7 和第 8 个组件,但第 9 个没有。我已经声明了变量,例如-
sud,eud,fud,a,e,c,d,na,st1,st2,citye,statee,pinne,cn,cr,cb,ca: array [0..9] of TEdit;
crr,vcl: array [0..9] of TEdit;
我在上面声明的所有其他组件都在该循环中成功创建。
crr[j+3]:=tEdit.Create(coregroup[i]);
crr[j+3].Parent:=coregroup[i];
crr[j+3].Top:= 77;
crr[j+3].Left:=83+(j*57);
crr[j+3].Width:=17;
我在过去两天的代码中处于同样的情况。如果需要更多说明,我可以提供给您。
实际代码是-
sud,eud,fud,a,e,c,d,na,st1,st2,citye,statee,pinne,cn,cr,cb,ca: array [0..9] of TEdit;
crr,vcl: array [0..9] of TEdit;
dud,leud,lfud,b,f,g,h,nal,st1l,st2l,cityel,stateel,pinnel,dt,cl,crl,cbl,cal,vce: array [0..9] of TLabel;
count,ppointer:integer;
rcaldt: array[0..5] of TDateTimePicker;
coregroup:array of TGroupBox;
var
i,j,kk,aa,x:integer;
divv:array[0..3] of Tlabel;
u,m,k:integer;
begin
k:=0;
m:=0;
//kk:=groupbox11.ControlCount-1;
SetLength(coregroup,5);
for i:=0 to count-1 do
begin
coregroup[i]:= tGroupbox.Create(groupbox11);
coregroup[i].Parent:=groupbox11;
coregroup[i].SetBounds(8+(i*223),140,x,170);
if ctvt.ItemIndex=0 then
coregroup[i].Caption:='C T'+ IntToStr((aa*i)+1)
else
coregroup[i].Caption:='V T'+ IntToStr((aa*i)+1);
cl[0]:= tLabel.Create(coregroup[i]);
cl[0].Parent:=coregroup[i];
cl[0].Top:= 20;
cl[0].Left:=8;
cl[0].Caption:= 'CORE';
cl[0].Font.Style := cl[0].Font.Style + [fsBold];
cbl[0]:= tLabel.Create(coregroup[i]);
cbl[0].Parent:=coregroup[i];
cbl[0].Top:= 50;
cbl[0].Left:=8;
cbl[0].Caption:= 'BURDEN';
cbl[0].Font.Style := cbl[0].Font.Style + [fsBold];
crl[0]:= tLabel.Create(coregroup[i]);
crl[0].Parent:=coregroup[i];
crl[0].Top:= 80;
crl[0].Left:=8;
crl[0].Caption:= 'RATIO';
crl[0].Font.Style := crl[0].Font.Style + [fsBold];
cal[0]:= tLabel.Create(coregroup[i]);
cal[0].Parent:=coregroup[i];
cal[0].Top:= 110;
cal[0].Left:=8;
cal[0].Caption:= 'ACLASS'; //cr,cb,ca
cal[0].Font.Style := cal[0].Font.Style + [fsBold];
vce[0]:= tLabel.Create(coregroup[i]);
vce[0].Parent:=coregroup[i];
vce[0].Top:= 140;
vce[0].Left:=8;
vce[0].Caption:= 'VCLASS'; //cr,cb,ca
vce[0].Font.Style := cal[0].Font.Style + [fsBold];
for j:=0 to ((StrToInt(ncorct.Text))-1) do
begin
if cn[j]=nil then
begin
cn[j]:=tEdit.Create(coregroup[i]);
cn[j].Parent:=coregroup[i];
cn[j].Top:= 17;
cn[j].Left:=52+(j*57);
cn[j].Width:=50;
cb[j]:=tEdit.Create(coregroup[i]);
cb[j].Parent:=coregroup[i];
cb[j].Top:= 47;
cb[j].Left:=71+(j*57);
cb[j].Width:=30;
cr[j]:=tEdit.Create(coregroup[i]);
cr[j].Parent:=coregroup[i];
cr[j].Top:= 77;
cr[j].Left:=56+(j*57);
cr[j].Width:=17;
ca[j]:=tEdit.Create(coregroup[i]);
ca[j].Parent:=coregroup[i];
ca[j].Top:= 107;
ca[j].Left:=61+(j*60);
ca[j].Width:=35;
divv[j]:=tLabel.Create(coregroup[i]);
divv[j].Parent:=coregroup[i] ;
divv[j].Top:=80;
divv[j].Left:=74+(j*57);
divv[j].Caption:='/';
crr[j]:=tEdit.Create(coregroup[i]);
crr[j].Parent:=coregroup[i];
crr[j].Top:= 77;
crr[j].Left:=83+(j*57);
crr[j].Width:=17;
vcl[j]:=tEdit.Create(coregroup[i]);
vcl[j].Parent:=coregroup[i];
vcl[j].Top:= 137;
vcl[j].Left:=61+(j*60);
vcl[j].Width:=35;
end
else
if cn[j+3]=nil then
begin
cn[j+3]:=tEdit.Create(coregroup[i]);
cn[j+3].Parent:=coregroup[i];
cn[j+3].Top:= 17;
cn[j+3].Left:=52+(j*57);
cn[j+3].Width:=50;
cb[j+3]:=tEdit.Create(coregroup[i]);
cb[j+3].Parent:=coregroup[i];
cb[j+3].Top:= 47;
cb[j+3].Left:=71+(j*57);
cb[j+3].Width:=30;
cr[j+3]:=tEdit.Create(coregroup[i]);
cr[j+3].Parent:=coregroup[i];
cr[j+3].Top:= 77;
cr[j+3].Left:=56+(j*57);
cr[j+3].Width:=17;
ca[j+3]:=tEdit.Create(coregroup[i]);
ca[j+3].Parent:=coregroup[i];
ca[j+3].Top:= 107;
ca[j+3].Left:=61+(j*60);
ca[j+3].Width:=35;
divv[j+3]:=tLabel.Create(coregroup[i]);
divv[j+3].Parent:=coregroup[i] ;
divv[j+3].Top:=80;
divv[j+3].Left:=74+(j*57);
divv[j+3].Caption:='/';
***crr[j+3]:=tEdit.Create(coregroup[i]);
crr[j+3].Parent:=coregroup[i];
crr[j+3].Top:= 77;
crr[j+3].Left:=83+(j*57);
crr[j+3].Width:=17;***
vcl[j+3]:=tEdit.Create(coregroup[i]);
vcl[j+3].Parent:=coregroup[i];
vcl[j+3].Top:= 137;
vcl[j+3].Left:=61+(j*60);
vcl[j+3].Width:=35;
end
else
begin
cn[j+6]:=tEdit.Create(coregroup[i]);
cn[j+6].Parent:=coregroup[i];
cn[j+6].Top:= 17;
cn[j+6].Left:=52+(j*57);
cn[j+6].Width:=50;
cb[j+6]:=tEdit.Create(coregroup[i]);
cb[j+6].Parent:=coregroup[i];
cb[j+6].Top:= 47;
cb[j+6].Left:=71+(j*57);
cb[j+6].Width:=30;
cr[j+6]:=tEdit.Create(coregroup[i]);
cr[j+6].Parent:=coregroup[i];
cr[j+6].Top:= 77;
cr[j+6].Left:=56+(j*57);
cr[j+6].Width:=17;
ca[j+6]:=tEdit.Create(coregroup[i]);
ca[j+6].Parent:=coregroup[i];
ca[j+6].Top:= 107;
ca[j+6].Left:=61+(j*60);
ca[j+6].Width:=35;
divv[j+3]:=tLabel.Create(coregroup[i]);
divv[j+3].Parent:=coregroup[i] ;
divv[j+3].Top:=80;
divv[j+3].Left:=74+(j*57);
divv[j+3].Caption:='/';
crr[j+6]:=tEdit.Create(coregroup[i]);
crr[j+6].Parent:=coregroup[i];
crr[j+6].Top:= 77;
crr[j+6].Left:=83+(j*57);
crr[j+6].Width:=17;
vcl[j+6]:=tEdit.Create(coregroup[i]);
vcl[j+6].Parent:=coregroup[i];
vcl[j+6].Top:= 137;
vcl[j+6].Left:=61+(j*60);
vcl[j+6].Width:=35;
end;
end;
end;
end
else
begin
one.Enabled:=false;
onem.Enabled:=false;
end;
end;