cnsuyong(小可) : Glad to meet you again!! 异常信息主要是: project project1.exe raised exception class EInvalidOperation with message 'Control'ListPicture1'has no parent window'....
//self.Parent:=AOwner as TWinControl; fImageList:=TImageList.Create(nil);
destructor TListPicture.Destroy; var i:integer; begin try if High(ArrayImage)<>-1 then begin for i:=low(ArrayImage) to high(ArrayImage) do ArrayImage[i].Free; ArrayImage:=nil; end; fImageChangeLink.Free; finally fImageList.Free;****************** inherited; end; end;
begin
inherited create(AOwner);
self.Parent:=AOwner as TWinControl;
fImageList:=TImageList.Create(self);
Height:=70;
Width:=400;
SelectedImageIndex:=-1;
canvas.Pen.Width:=2;
OnResize:=DoReSize;
fImageSize:=50; fImageChangeLink:=TChangeLink.Create;
fImageChangeLink.OnChange:=ImageListChanged;
end;
Glad to meet you again!!
异常信息主要是: project project1.exe raised exception class EInvalidOperation with message 'Control'ListPicture1'has no parent window'....
//self.Parent:=AOwner as TWinControl;
fImageList:=TImageList.Create(nil);
至于ImageList在创建时是否需要指定Owner,俺以为最好是指定。指定为nil是不安全的,因为这样做将可能导致在应用程序运行期间,如果你没有及时释放对象实例,那么势必造成内存丢失(暂时的),这些丢失直到你的应用程序结束才会被操作系统收回(准确地说是Delphi自动释放所有相关资源,包括开发者在应用程序中忘记释放的对象实例)。为对象实例指定Owner,那么就应该在Owner被销毁之前销毁该对象。俺看过了,你的源代码中没有这些问题。
祝你好运!
var i:integer;
begin
try
if High(ArrayImage)<>-1 then
begin
for i:=low(ArrayImage) to high(ArrayImage) do
ArrayImage[i].Free;
ArrayImage:=nil;
end;
fImageChangeLink.Free;
finally
fImageList.Free;******************
inherited;
end;
end;