Question

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?

Était-ce utile?

La solution

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;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top