Reputation: 18712
I have an instance of TComponent
class and need to interact with the respective control via WinAPI calls.
In order to do this, I need a handle of the control represented by TComponent
instance.
How can I get that handle from TComponent
?
Upvotes: 1
Views: 3897
Reputation: 2582
Try casting your TComponent instance to TWinControl.
Untested if it returns valid handles, but it's returning plausible numbers.
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
mycontrol: TWinControl;
begin
Memo1.Lines.Clear;
for i := 0 to ComponentCount - 1 do
if Components[i] is TWinControl then
begin
mycontrol := TWinControl(Components[i]);
Memo1.Lines.Add(IntToStr(mycontrol.Handle));
end;
end;
Upvotes: 4