albertovesx Posted March 15, 2017 Share Posted March 15, 2017 Can I use this method to find a component in runtime? It coud raise a memory leak or something? var i: Integer; c: TUniDBCheckBox; begin for i := 1 to 20 do begin c := FindComponent('somename' + i.toString) as TuniDBCheckBox; if c <> nil then begin if c.checked then dosomething; end; end; end; Quote Link to comment Share on other sites More sharing options...
Hayri ASLAN Posted March 17, 2017 Share Posted March 17, 2017 Yes, You can use it. 1 Quote Link to comment Share on other sites More sharing options...
GerhardV Posted March 17, 2017 Share Posted March 17, 2017 Maybe don't do the "as TUniDBCheckBox" where you execute FindComponent....but do a sanity check if the component "is TUniDBcheckBox" first. var i: Integer; c: TComponent; <<---- use TComponent here begin for i := 1 to 20 do begin c := FindComponent('somename' + i.toString); if (c <> nil) and (c is TUniDBCheckBox) then <<---- sanity check here begin if (c as TUniDBCheckBox).checked then <<---- cast here dosomething; end; end; end; 1 Quote Link to comment Share on other sites More sharing options...
albertovesx Posted March 17, 2017 Author Share Posted March 17, 2017 Ok, Thank you both 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.