[Lazarus] how to get Type of Sender or Components[i] in order to Cast?

JuuS JuuS at mykolab.ch
Mon Jul 27 10:58:27 CEST 2015



On 07/27/2015 09:31 AM, Mark Morgan Lloyd wrote:
> Péter Gábor wrote:
>> Sorry!
>> I was "misreading" your mail... you want to know the type of them.
>>
>> You can compare the type of them:
>>
>> if Sender = TButton then { do something} ;
> 
> Can this be elegantly put into a case statement?
> 
Hi, I just tried it and no you can't. At least not directly, there may
be a way of casting the Sender object to ordinal or string but I'm not
sure that is efficient or elegant.

Why not simply iterate the control List:

for i := 0 to Controls.Count - 1 do
begin
  If controls[ i ] is TCheckbox then
    TCheckbox( Controls[ i ] ).Checked := ....
end;




More information about the Lazarus mailing list