B
book523
Unregistered / Unconfirmed
GUEST, unregistred user!
写了一个简单控件,
显示时间的label,
可是还有2个问题:
1。timer属性在设计时,修改不起作用,总是等于1899-12-30+系统时间
2。把该控件拖到窗体上时,caption为timepanel+序号,为什么不等于系统时间(我在
create事件中已经设置了);
3。把该控件从窗体上删除时,会发生错误,好像是地址访问错误,是不是timer的
释放方法不对,应该怎么释放?
unit MyCustomPanel;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls,DateUtils;
type
TTimePanel = class(TCustomPanel)
private
{ Private declarations }
FTime:TTime;
FMyTimer:TTimer;
procedure Ontimer(Sender:TObject);
procedure SetTime(value:TTime);
protected
{ Protected declarations }
public
property DockManager;
constructor Create(AOwner: TComponent); override;
Destructor Destroy;Override;
procedure ResetTime;
{ Public declarations }
published
{ Published declarations }
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BevelInner;
property BevelOuter;
property BevelWidth;
property BiDiMode;
property BorderWidth;
property BorderStyle;
property Caption;
property Color;
property Constraints;
property Ctl3D;
property UseDockManager default True;
property DockSite;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FullRepaint;
property Font;
property Locked;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
property Time:TTime Read FTime Write SetTime;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('hxw', [TTimePanel]);
end;
Constructor TTimePanel.Create(AOwner:TComponent);
begin
Inherited;
FMyTimer:=TTimer.Create(self);
FMyTimer.Interval:=1000;
FMyTimer.Ontimer:=OnTimer;
FMyTimer.Enabled:=True;
Ftime:=SysUtils.Time;
Caption:=TimeToStr(Ftime);
end;
Destructor TTimePanel.Destroy;
begin
FMyTimer.Free;
Inherited;
end;
procedure TTimePanel.SetTime(Value:TTime);
begin
if FTime <> Value then
begin
Ftime:=Value;
Caption:=TimeToStr(FTime);
end;
end;
procedure TTimePanel.OnTimer(Sender:Tobject);
var
T:TDateTime;
begin
T:=FTime;
FTime:=IncSecond(T,1);
Caption:=TimeToStr(FTime);
end;
procedure TTimePanel.ResetTime ;
begin
Ftime:=StrToTime('00:00:00');
Caption:='00:00:00';
end;
end.
显示时间的label,
可是还有2个问题:
1。timer属性在设计时,修改不起作用,总是等于1899-12-30+系统时间
2。把该控件拖到窗体上时,caption为timepanel+序号,为什么不等于系统时间(我在
create事件中已经设置了);
3。把该控件从窗体上删除时,会发生错误,好像是地址访问错误,是不是timer的
释放方法不对,应该怎么释放?
unit MyCustomPanel;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls,DateUtils;
type
TTimePanel = class(TCustomPanel)
private
{ Private declarations }
FTime:TTime;
FMyTimer:TTimer;
procedure Ontimer(Sender:TObject);
procedure SetTime(value:TTime);
protected
{ Protected declarations }
public
property DockManager;
constructor Create(AOwner: TComponent); override;
Destructor Destroy;Override;
procedure ResetTime;
{ Public declarations }
published
{ Published declarations }
property Align;
property Alignment;
property Anchors;
property AutoSize;
property BevelInner;
property BevelOuter;
property BevelWidth;
property BiDiMode;
property BorderWidth;
property BorderStyle;
property Caption;
property Color;
property Constraints;
property Ctl3D;
property UseDockManager default True;
property DockSite;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FullRepaint;
property Font;
property Locked;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
property Time:TTime Read FTime Write SetTime;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('hxw', [TTimePanel]);
end;
Constructor TTimePanel.Create(AOwner:TComponent);
begin
Inherited;
FMyTimer:=TTimer.Create(self);
FMyTimer.Interval:=1000;
FMyTimer.Ontimer:=OnTimer;
FMyTimer.Enabled:=True;
Ftime:=SysUtils.Time;
Caption:=TimeToStr(Ftime);
end;
Destructor TTimePanel.Destroy;
begin
FMyTimer.Free;
Inherited;
end;
procedure TTimePanel.SetTime(Value:TTime);
begin
if FTime <> Value then
begin
Ftime:=Value;
Caption:=TimeToStr(FTime);
end;
end;
procedure TTimePanel.OnTimer(Sender:Tobject);
var
T:TDateTime;
begin
T:=FTime;
FTime:=IncSecond(T,1);
Caption:=TimeToStr(FTime);
end;
procedure TTimePanel.ResetTime ;
begin
Ftime:=StrToTime('00:00:00');
Caption:='00:00:00';
end;
end.