Result:=TPanel.Create(pnButton);
With Result do
begin
Name:='BrowserButton'+IntToStr(pnButton.ComponentCount);
Parent:=pnButton;
Caption:=ButtonCaptions[I];
BevelOuter:=bvNone;
Color:=$DEDEDE;
Top:=0;
Height:=ButtonHeight;
Width:=MinButtonWidth;
ShowHint:=True;
PopupMenu:=ButtonPopupMenu;
OnMouseDown:=BrowserButtonMouseDown;
Tag:=pnButton.ComponentCount;
end;
sp:=TShape.Create(Result);
With sp do
begin
Name:='ShapeBrowserButton'+IntToStr(pnButton.ComponentCount);
Parent:=Result;
Brush.Style:=bsClear;
Align:=alClient;
end;
If pnButton.ComponentCount>1 then
begin
im:=TImage.Create(Result);
With im do
begin
Name:='imCloseButtonBrowserButton'+IntToStr(pnButton.ComponentCount);
Parent:=Result;
Transparent:=True;
imCloseButtons.GetBitmap(0,im.Picture.Bitmap);
AutoSize:=True;
Left:=sp.Width-Width-Delta-1;
Top:=(sp.Height-Height) shr 1;
Anchors:=[akTop,akRight];
OnMouseClick:=imCloseButtonClick;
end;
end;
//Обрабботка нажатия на Image
procedure Tfm.imCloseButtonClick(Sender: TObject);
begin
TImage(Sender).Parent.Free;
end;<<------ Ошибка после выполнения этой строки
В результате ошибка при выходе из процедуры, сама строка TImage(Sender).Parent.Free; выполняется нормально, причем все убивается хорошо.
блин... вот она лень-матушка... до конца то я не дочитал... сорри
Warning: Never explicitly free a component within one of its own event handlers or free a component from the event handler of a component it owns or contains. For example, don’t free a button in its OnClick event handler or free the form that owns the button from the button's OnClick event.
const WM_MYDESTROYPANEL = WM_USER + $100;
procedure TForm1.Image1Click(Sender: TObject);
begin
PostMessage(Self.Handle, WM_MYDESTROYPANEL, 0, 0);
end;
procedure TForm1.WndProc(var Message: TMessage); // ! override !
begin
if WM_MYDESTROYPANEL = Message.Msg then
Image1.Parent.Free
else
inherited;
end;
Суть в том, чтобы развести по времени запрос на удаление и само уничтожение родительского контрола, т.е. вынести из обработчика Image1Click() - там некорректно.