質問

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?

役に立ちましたか?

解決

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;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top