W
wallysw
Unregistered / Unconfirmed
GUEST, unregistred user!
我在自定义一个组件时,在设计期间,把组件放到FORM1里,拖动Labelededit时,为什么speedbutton不跟它走动啊?完整代码如下:
---------------------------------------------
unit edop;
interface
uses
SysUtils, Classes, Controls, StdCtrls, ExtCtrls, Buttons;
type
Tedop = class(TLabeledEdit)
private
BTN: TSpeedButton;
FBtnVisible: Boolean;
procedure SetVisible(const Value: boolean);
procedure SetLeft(const Value: integer);
procedure SetTop(const Value: integer);
function GetTop:integer;
function GetLeft:integer;
{ Private declarations }
protected
{ Protected declarations }
public
constructor Create(AOWner: TComponent);override;
Destructor Destroy;override;
{ Public declarations }
published
property BtnVisible: boolean read FBtnVisible write SetVisible;
property Top: integer read GetTop write SetTop;
property Left: integer read GetLeft write SetLeft;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [Tedop]);
end;
{ Tedop }
constructor Tedop.Create(AOWner: TComponent);
begin
inherited Create(AOWner);
end;
destructor Tedop.Destroy;
begin
BTN.Free;
inherited Destroy;
end;
function Tedop.GetLeft: integer;
begin
result := inherited Left;
end;
function Tedop.GetTop: integer;
begin
result := inherited Top;
end;
procedure Tedop.SetLeft(const Value: integer);
begin
inherited Left := Value;
btn.Left := Value + Width;
end;
procedure Tedop.SetTop(const Value: integer);
begin
inherited Top := Value;
btn.Top := Value;
end;
procedure Tedop.SetVisible(const Value: boolean);
begin
FBtnVisible := Value;
if Value then
begin
BTN := TSpeedButton.Create(Self);
BTN.Left := Self.Left + Self.Width;
BTN.Top := Self.Top;;
BTN.Parent := Self.Parent;
end else
begin
BTN.Free;
end;
end;
end.
---------------------------------
望哪位大哥大姐帮我解决一下。谢谢。
---------------------------------------------
unit edop;
interface
uses
SysUtils, Classes, Controls, StdCtrls, ExtCtrls, Buttons;
type
Tedop = class(TLabeledEdit)
private
BTN: TSpeedButton;
FBtnVisible: Boolean;
procedure SetVisible(const Value: boolean);
procedure SetLeft(const Value: integer);
procedure SetTop(const Value: integer);
function GetTop:integer;
function GetLeft:integer;
{ Private declarations }
protected
{ Protected declarations }
public
constructor Create(AOWner: TComponent);override;
Destructor Destroy;override;
{ Public declarations }
published
property BtnVisible: boolean read FBtnVisible write SetVisible;
property Top: integer read GetTop write SetTop;
property Left: integer read GetLeft write SetLeft;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [Tedop]);
end;
{ Tedop }
constructor Tedop.Create(AOWner: TComponent);
begin
inherited Create(AOWner);
end;
destructor Tedop.Destroy;
begin
BTN.Free;
inherited Destroy;
end;
function Tedop.GetLeft: integer;
begin
result := inherited Left;
end;
function Tedop.GetTop: integer;
begin
result := inherited Top;
end;
procedure Tedop.SetLeft(const Value: integer);
begin
inherited Left := Value;
btn.Left := Value + Width;
end;
procedure Tedop.SetTop(const Value: integer);
begin
inherited Top := Value;
btn.Top := Value;
end;
procedure Tedop.SetVisible(const Value: boolean);
begin
FBtnVisible := Value;
if Value then
begin
BTN := TSpeedButton.Create(Self);
BTN.Left := Self.Left + Self.Width;
BTN.Top := Self.Top;;
BTN.Parent := Self.Parent;
end else
begin
BTN.Free;
end;
end;
end.
---------------------------------
望哪位大哥大姐帮我解决一下。谢谢。