As I understand it, there are two different ways of doing a cast in pascal
1) the 'as' keyword eg Result := LCLObject as TWinControl;
Only available for classes (and interfaces). It checks if lclobject is a TWincontrol and throws an exception otherwise.
2) using brackets, so the above example is
Result := TWinControl(LCLObject);
First. This is only a (true) cast if sizeof(result)=sizeof(twincontrol)=sizeof(lclobject), otherwise it is a conversion.
It helps to view (true) casts as "let the compiler reinterpret a piece of memory in a different way described by this type"
Is there / should there be any difference between these methods?
Yes, this does always assign, and no checking. So it will put lclobject into result even if it is not twincontrol
I ask because when in debug mode , I get an invalid cast error with the first method at lcl/interfaces/gtk2/gtk2cellrenderer.pas line92 , but the second works fine.
This is the reason to use AS. If something is wrong, you get a warning. Casting, while removing the warning will pass on corrupt data.
Solution: fix the original problem, and make sure it IS truly a twincontrol