tcomponent实例的句柄



我有一个TComponent类的实例,需要通过Winapi调用与相应的控件进行交互。

为了做到这一点,我需要一个由TComponent实例表示的控件的句柄。

如何从TComponent获得该处理?

尝试将您的tcomponent实例投射到twincontrol。

未测试如果返回有效手柄,但它返回了合理的数字。

 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;

最新更新