Skepsis IT Posted October 29, 2013 Share Posted October 29, 2013 Hi everybody, I face a very strange problem, I create some components dynamically using dynamic array using the same way for all of it (unilabel,unidatetimepicker and uniedit). For example: datearray[I]:=TUniDateTimePicker.Create(self); datearray[I].Parent:=FldsPanel; datearray[I].Width:=150; datearray[I].Left:=left; datearray[I].Top:=top; of course, above code goes in a for loop... I free all of them the same way For example: for cnt := Low(datearray) to High(datearray) do begin datearray[cnt].Free; datearray[cnt] := nil; end; The strange thing is that unidatetimepicker and unilabel array free up ok, uniedit array don't and of course I have an error when I close the form that contains them.Do you have any clue? Tip: when I debug, I see that when I create components on the other arrays gets value (eg. $xxxxxxxx) but on tuniedit array gets nil. Link to comment Share on other sites More sharing options...
lema Posted October 29, 2013 Share Posted October 29, 2013 Hi ,can you send a simple test case for this issue? Link to comment Share on other sites More sharing options...
Sherzod Posted October 30, 2013 Share Posted October 30, 2013 Hi skepsis. First try this: datearray:=TUniDateTimePicker.Create(self); specify nil, instead self datearray[I] := TUniDateTimePicker.Create(NIL); or datearray[I] := TUniEdit.Create(NIL); ... Secondly: when (where) you destroy objects? Sincerely Link to comment Share on other sites More sharing options...
Skepsis IT Posted October 30, 2013 Author Share Posted October 30, 2013 Hi, and thanks for your replies! lema, I'll try to prepare a test case for upload. Delphi developer, I have already tried nil before posting in the forum and I got a Fatal Error: Control can not be constructed with a nil Owner, actually nil not proper for controls on a form. I've made a procedure that destroys the object, firstly I call this procedure at forms OnClose event, but for test purposes I add a button that calls it. Same results. Link to comment Share on other sites More sharing options...
Sherzod Posted October 30, 2013 Share Posted October 30, 2013 can give a test case? Link to comment Share on other sites More sharing options...
Skepsis IT Posted October 30, 2013 Author Share Posted October 30, 2013 Lema, I started a test case and I realize that all the uniedit objects that are created after unidatetimepicker objects cannot be deleted. I paste a piece of code for better understanding if (Grd.Columns[I].Field.DataType=ftDate) or (Grd.Columns[I].Field.DataType=ftDateTime) then begin inc(datecnt); SetLength(datearray,datecnt); datearray[I]:=TUniDateTimePicker.Create(self); datearray[I].Parent:=FldsPanel; datearray[I].Width:=150; datearray[I].Left:=left; datearray[I].Top:=top; datearray[I].TabOrder:=I; end else begin inc(editcnt); SetLength(editarray,editcnt); editarray[I]:=TUniEdit.Create(self); editarray[I].Name:='UniEdit'+inttostr(editcnt); editarray[I].Text:=inttostr(editcnt); editarray[I].Parent:=FldsPanel; editarray[I].Width:=150; editarray[I].Left:=left; editarray[I].Top:=top; editarray[I].TabOrder:=I; end; Link to comment Share on other sites More sharing options...
Skepsis IT Posted October 30, 2013 Author Share Posted October 30, 2013 I uploaded a test case. testarray.zip Link to comment Share on other sites More sharing options...
Skepsis IT Posted October 30, 2013 Author Share Posted October 30, 2013 Oops I found it! I use variable I as index to all arrays!!! Firstly thanks for your help and sorry for your loss of time! Link to comment Share on other sites More sharing options...
Sherzod Posted October 30, 2013 Share Posted October 30, 2013 procedure TMainForm.CreateComponents(Grd: TUniDBGrid); var I,editcnt,datecnt,labelcnt,top,fldcnt: Integer; begin labelcnt:=0; datecnt:=0; editcnt:=0; top:=50; left:=16; fldcnt:=0; for I := 0 to Grd.Columns.Count - 1 do begin inc(labelcnt); SetLength(labels,labelcnt); labels:=TUniLabel.Create(self); labels.Parent:=FldsPanel; labels.Top:=top-19; labels.Left:=left; labels.Caption:=Grd.Columns.Title.Caption; if (Grd.Columns.Field.DataType=ftDate) or (Grd.Columns.Field.DataType=ftDateTime) then begin inc(datecnt); SetLength(datearray,datecnt); datearray[datecnt-1]:=TUniDateTimePicker.Create(self); datearray[datecnt-1].Parent:=FldsPanel; datearray[datecnt-1].Width:=150; datearray[datecnt-1].Left:=left; datearray[datecnt-1].Top:=top; datearray[datecnt-1].TabOrder:=I; end else begin inc(editcnt); SetLength(editarray,editcnt); editarray[editcnt-1]:=TUniEdit.Create(self); editarray[editcnt-1].Name:='UniEdit'+inttostr(editcnt); editarray[editcnt-1].Parent:=FldsPanel; editarray[editcnt-1].Width:=150; editarray[editcnt-1].Left:=left; editarray[editcnt-1].Top:=top; editarray[editcnt-1].TabOrder:=I; end; left:=left+156; inc(fldcnt); // УФБ 5 РЕДЙБ КБФЕВБЙНЩ ГСБММЗ if fldcnt = 5 then begin top:=top+56; fldcnt:=0; left:=16; end; end; // end of for I end; Link to comment Share on other sites More sharing options...
Skepsis IT Posted October 30, 2013 Author Share Posted October 30, 2013 Yes my friend exactly! Some things are in front of your eyes, but you can't see them. 1 Link to comment Share on other sites More sharing options...
Skepsis IT Posted October 30, 2013 Author Share Posted October 30, 2013 for I := 0 to Grd.Columns.Count - 1 do begin inc(labelcnt); SetLength(labels,labelcnt); labels[I]:=TUniLabel.Create(self); labels[I].Parent:=FldsPanel; labels[I].Top:=top-19; labels[I].Left:=left; labels[I].Caption:=Grd.Columns[I].Title.Caption; if (Grd.Columns[I].Field.DataType=ftDate) or (Grd.Columns[I].Field.DataType=ftDateTime) then begin inc(datecnt); SetLength(datearray,datecnt); datearray[datecnt-1]:=TUniDateTimePicker.Create(self); datearray[datecnt-1].Name:=Grd.Columns[I].FieldName; datearray[datecnt-1].Parent:=FldsPanel; datearray[datecnt-1].Width:=150; datearray[datecnt-1].Left:=left; datearray[datecnt-1].Top:=top; datearray[datecnt-1].TabOrder:=I; end else begin inc(editcnt); SetLength(editarray,editcnt); editarray[editcnt-1]:=TUniEdit.Create(self); editarray[editcnt-1].Name:=Grd.Columns[I].FieldName; editarray[editcnt-1].Name:='UniEdit'+inttostr(editcnt); editarray[editcnt-1].Parent:=FldsPanel; editarray[editcnt-1].Width:=150; editarray[editcnt-1].Left:=left; editarray[editcnt-1].Top:=top; editarray[editcnt-1].TabOrder:=I; end; left:=left+156; inc(fldcnt); if fldcnt = 5 then begin top:=top+56; fldcnt:=0; left:=16; end; end; // end of for I end; Link to comment Share on other sites More sharing options...
lema Posted October 30, 2013 Share Posted October 30, 2013 Some things are in front of your eyes, but you can't see them. I know , I know. We've all had such a bad day.... Link to comment Share on other sites More sharing options...
Jancarlos Martins Posted October 30, 2013 Share Posted October 30, 2013 Hi, I use generics.collections, very simple. http://docwiki.embarcadero.com/CodeExamples/XE5/en/Generics_Collections_TList_(Delphi) Link to comment Share on other sites More sharing options...
rasaliad Posted April 29, 2017 Share Posted April 29, 2017 Hi, I use generics.collections, very simple. http://docwiki.embarcadero.com/CodeExamples/XE5/en/Generics_Collections_TList_(Delphi) Hi, perjanbr Can you please, give a sample with generics.collections, to create/destroy components at runtime. Thanks, Liriano Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now