Find Component as TWincontrol at runtime
Posted on 2008-11-04
I need to run a procedure, that takes a control for the first parameter. The control is created at runtime.
Here's my procedure:
procedure SetElevationRequiredState(aControl: TWinControl; Required: Boolean);
lRequired := Integer(Required);
SendMessage(aControl.Handle, BCM_SETSHIELD, 0, lRequired);
Here's how I'm calling it it my program:
SetElevationRequiredState( TWinControl(FindComponent('G4_Button7')), True);
When I run it in the debugger, I get something like: "First chance exception at $7C812AEB. Exception class EAccessViolation with message 'Access violation at address 004BDF0F in module 'runtime.exe'. Read of address 000001B4'. Process runtime.exe (3224)"
How can I run this procedure using the control as the first parameter?