MarkLince Posted February 21, 2017 Share Posted February 21, 2017 Hi, I have a Frame with a scrollbox on it and some labels and listboxes on the scrollbox. The labels and listboxes are named ADLabel1, ADlabel2, ADLabel3 .... and similarly the listboxes. trying to cycle through the controls and change properties using for example; for count1:= 0 to mystringlist.count-1 do begin TUniLabel(FindComponent('ADLabel'+inttostr(count1+1))).caption:=mystringlist[count1]; end; But this causes an AV, searched through forum and fincomponent seems to have been a problem in early builds of uniGUI, is it still a problem?? I have tried lots of variations of findcomponent but nothing seems to work. So... any help is gratefully received. Regards Mark Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted February 21, 2017 Administrators Share Posted February 21, 2017 FindComponent returns NIL when it can not find the component. Can it be the case? Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted February 21, 2017 Administrators Share Posted February 21, 2017 Also make sure you call FindComponent of the correct Owner. Quote Link to comment Share on other sites More sharing options...
MarkLince Posted February 21, 2017 Author Share Posted February 21, 2017 Hi Farshad, Thanks for a quick reply, yes as you say, findcomponent is returning nil and therefore causes AV in my code sample. I have also tried; var ADlabel:Tunilabel; ADLabel:=TUniLabel(ADScroll1.FindComponent('ADLabel'+inttostr(count1+1))); if not (AdLabel = nil) then begin ADLabel.Caption:='Test'; end; and of course no AV and caption is not set as ADLabel is nil, but I don't understand why it should be nil. as there is a component called "ADLabel1, ADLabel2, ....." with parent ADScroll1 What am I missing? Thanks Mark Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted February 21, 2017 Administrators Share Posted February 21, 2017 How ADLabel(s) are created? Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted February 21, 2017 Administrators Share Posted February 21, 2017 ADScroll1.FindComponent Here is the issue. ADScroll1 is the parent not the owner. FindComponent only works for owner of the control. Quote Link to comment Share on other sites More sharing options...
MarkLince Posted February 21, 2017 Author Share Posted February 21, 2017 Hi Farshad, Thanks again for your help, I feel silly I missed that!! This works ADLabel:=TUniLabel(ADScroll1.owner.FindComponent('ADLabel'+inttostr(count1+1))); Regards Mark Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.