delphi 接口说明 及FindControl

type
 IShape=interface
end;
 ICircle = Interface(IShape)
end;

TBoll = class(TInterfaceObject, ICircle)
end;

1. 接口继承只是输入上的便利,不必再重复录入。并没有继承关系。 TBoll 实现了ICirle,但并没有实现 IShape. 要实现IShape, 则需要显示 TBoll=class(..,ICirle, IShaple).

2. 通过as可以进行接口与类型之间的互相转换。

var
  a:IA;
  b:IB;
  c,t : TB;
  o:Integer;
  i:IInterface;
  obj:TObject;
begin
  c := TB.Create;
  i := c;   //直接通过对象赋值给接口
  o := Integer(c);
  o := Integer(i);
  i := IInterface(o);  
  b := i as IB;  //接口互转
  a := i as IA;
  a := b as IA;
  b := a as IB;
  b := c;
  a := c;
  obj := b as TObject;  //接口转对象

在vcl.controls单元有几个有用的函数

function IsDragObject(Sender: TObject): Boolean;
function IsVCLControl(Handle: HWND): Boolean;
//当控件释放后,通过这个可以判断控件是否已释放。变相实现检测方法。
function FindControl(Handle: HWND): TWinControl;
function FindVCLWindow(const Pos: TPoint): TWinControl;
function FindDragTarget(const Pos: TPoint; AllowDisabled: Boolean): TControl;
function GetCaptureControl: TControl;
procedure SetCaptureControl(Control: TControl);
procedure CancelDrag;
  obj := b as TObject;
  btn := TButton.Create(nil);
  btn.Parent := Self;  //如果不指定parent, 则btn不创建handle.
  m := Handle;
  m := btn.Handle;
  w := FindControl(m);  //w=btn
  btn.free;
  w :=  FindControl(m);  //w = nil

你可能感兴趣的:(delphi,delphi)