如果我直接将两个控件放到TForm上,通过Form能实现复合控件的功能吗.
--肯定可以
--写个简单关联的例子给你
unit MyEdit;
interface
uses
SysUtils, Classes, Controls, StdCtrls;
type
TMyEdit = class(TEdit)
private
FLinkLabel: TLabel;
procedure FSetLinkLabel(AValue: TLabel);
protected
procedure Notification(AComponent: TComponent;Operation: TOperation);
override;
procedure Change;override;
public
published
property LinkLabel: TLabel read FLinkLabel write FSetLinkLabel;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Linco', [TMyEdit]);
end;
procedure TMyEdit.Change;
begin
inherited;
if LinkLabel <> nil then
LinkLabel.Caption := Text;
end;
procedure TMyEdit.FSetLinkLabel(AValue: TLabel);
begin
FLinkLabel := AValue;
if AValue <> nil then
FLinkLabel.FreeNotification(self);//关联后要通知
end;
procedure TMyEdit.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited;
if (Operation = opRemove) and (AComponent = LinkLabel) then
//删除关联也要通知
LinkLabel := nil;
end;
end.