我做了一个由TComponent继承,在Create时我修改了它所在窗体的Caption,可是删掉它后Cation不能还原 (100分)

  • 主题发起人 主题发起人 HeXiang Lee
  • 开始时间 开始时间
H

HeXiang Lee

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个由TComponent继承,在Create时我修改了它所在窗体的Caption,
可是删掉它后Cation不能还原

Type mycomp=(Tcomponent)
protect
oldCaption:String;
......
public
constructor create(Owner:Tcomponent);Override; //在这个事件里可以改原来
//窗口的Caption;
destructor destory; //这个事件好像不去执行 ?????
..........
请高手指点!
 
把你的贴出来?
 
實際上我提問時換了一個提法﹐實際上是一樣的。
以下是我寫的一個控件﹐我想做一個能實現超級解霸那個不斷的更換ICON

unit HxAnimateIcon;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,extctrls;

type
tHxAnimateIcon = class(tcomponent)
private
FImageList: TImageList;
FAnimate: Boolean;
FSpeed: Integer;
CurImageId:Integer;
AnimateWindow:TForm;
FAbout: TCollection;
OldWindowIcon:TIcon;
OldApplicationIcon:TIcon;
FEnableAnimateAppIcon: Boolean;
procedure SetImageList(const Value: TImageList);
procedure SetAnimate(const Value: Boolean);
procedure SetSpeed(const Value: Integer);
procedure SetAbout(const Value: TCollection);
procedure SetEnableAnimateAppIcon(const Value: Boolean);
{ Private declarations }
protected
{ Protected declarations }
Timer:TTimer;
procedure Ontimer(Sender:TObject);
public
constructor Create(Owener:TComponent);override;
destructor Destory;
{ Public declarations }
published
{ Published declarations }
property ImageList:TImageList read FImageList write SetImageList;
property Animate:Boolean read FAnimate write SetAnimate;
property EnableAnimateAppIcon:Boolean read FEnableAnimateAppIcon write SetEnableAnimateAppIcon;
property Speed:Integer read FSpeed write SetSpeed;
property About:TCollection read FAbout write SetAbout;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Holy Soft', [tHxAnimateIcon]);
end;

{ tHxAnimateIcon }

constructor tHxAnimateIcon.Create(Owener: TComponent);
var
I:Integer;
begin
if not (Owener is TForm) then
Begin
ShowMessage('This Component is only on a form!');
Abort;
Exit;
end;
for I:=0 to (Owener As TForm).ComponentCount-1 do
if (Owener As TForm).Components is tHxAnimateIcon then
Begin
ShowMessage('There is alredy have a tHxAnimateIcon on this form﹐'+#13+'Can''t have an other one!');
Abort;
Exit;
end;
inherited Create(Owener);
Self.AnimateWindow:=(Owener As TForm);

self.OldWindowIcon:=TIcon.create;
self.OldApplicationIcon:=TIcon.Create ;
self.OldWindowIcon.Assign(self.Animatewindow.Icon);
self.OldApplicationIcon.Assign(Application.Icon);

Self.CurImageId :=0;
Self.Speed :=1000;
Self.Animate :=True;

Self.ImageList:=TImageList.Create(Self);
Self.ImageList:=nil;
Timer:=TTimer.Create(Self);
Timer.Interval :=Self.Speed ;
Timer.Enabled :=Self.Animate ;
Timer.OnTimer:=Self.Ontimer ;
end;





destructor tHxAnimateIcon.Destory;
begin
Timer.Free;
ImageList.Free;
showMessage('asfasfd');
self.AnimateWindow.icon.assign(self.OldWindowIcon);
application.Icon.Assign(self.oldApplicationIcon);
self.OldWindowIcon.free;
self.OldApplicationIcon.free;
end;

procedure tHxAnimateIcon.Ontimer(Sender: TObject);
var
temIcon:TIcon;
begin
if Self.FImageList<>nil then
begin
Self.CurImageId:=Self.CurImageId+1;
if Self.CurImageId>FImageList.Count-1 then
Self.CurImageId:=0;
temIcon:=TIcon.Create ;

FImageList.GetIcon(CurImageId,temIcon);
Self.AnimateWindow.Icon.Assign(temIcon);
if self.EnableAnimateAppIcon then
application.Icon.Assign(temIcon);
temIcon.Free;
end;
end;

procedure tHxAnimateIcon.SetAbout(const Value: TCollection);
begin

end;

procedure tHxAnimateIcon.SetAnimate(const Value: Boolean);
begin
FAnimate := Value;
If Not Value then
begin
self.AnimateWindow.Icon.Assign(self.OldWindowIcon );
application.Icon.Assign(self.oldApplicationIcon);
end;

if Timer<>nil then
Timer.Enabled :=Value;
end;



procedure tHxAnimateIcon.SetEnableAnimateAppIcon(const Value: Boolean);
begin
FEnableAnimateAppIcon := Value;
If Not Value then
Application.Icon.Assign(self.OldApplicationIcon );

end;

procedure tHxAnimateIcon.SetImageList(const Value: TImageList);
begin
FImageList := Value;
end;

procedure tHxAnimateIcon.SetSpeed(const Value: Integer);
begin
FSpeed := Value;
if Timer<>nil then
Timer.Interval :=Value;
end;

end.
 
destructor tHxAnimateIcon.Destory;
begin
Timer.Free;
ImageList.Free;
showMessage('asfasfd');
self.AnimateWindow.icon.assign(self.OldWindowIcon);
application.Icon.Assign(self.oldApplicationIcon);
self.OldWindowIcon.free;
self.OldApplicationIcon.free;

inherited Destroy; //是不是需要继承一下
end;
 
destructor destory; //这个事件好像不去执行 ?????
===>
destructor destory; override;
 
加Override不行的﹐加了以后會出現Destory在Component的父類里不存在.
 
如果Override不行就用reintroduce吧!将隐藏祖先类的同名方法
 
HeXiang Lee,你自己该打屁股!你看看你的Destroy,你自己写成了Destory!!!!!当然不行!
我照着改过了后,当我删除该控件时,就激发Destroy事件了.显示'asfasfd'了.
呵呵,改过来吧.
destructor tHxAnimateIcon.Destroy;

destructor tHxAnimateIcon.Destroy;
begin
Timer.Free;
ImageList.Free;
showMessage('asfasfd');
self.AnimateWindow.icon.assign(self.OldWindowIcon);
application.Icon.Assign(self.oldApplicationIcon);
self.OldWindowIcon.free;
self.OldApplicationIcon.free;
inherited;
end;
 
destory改為
destroy就ok了
 
謝謝大家
真的該死﹐就寫錯一個單詞
屁股也打了﹐分也沒了﹗﹗﹗﹗
 
后退
顶部