AlbertoVesx Posted March 15, 2017 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
GerhardV Posted March 17, 2017 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
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.