ToolBar释放问题!
国风 2004-12-09 02:10:24 ToolBar上的ToolButton单击后要刷新窗体重新创建ToolBar,问题是在单击事件后释放ToolBar时常会出问题,请高手指点!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ToolWin, ComCtrls, StdCtrls, Buttons;
type
TForm1 = class(TForm)
CoolBar1: TCoolBar;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
procedure ToolBarClick(Sender: TObject);
public
{ Public declarations }
end;
var
Form1: TForm1;
ToolBar : TToolBar;
TBtn : TToolButton;
implementation
{$R *.dfm}
procedure TForm1.ToolBarClick(Sender: TObject);
begin
if (Sender is TToolButton) then
begin
if (Sender as TToolButton).Name = 'Btn1' then
begin
Form1.Hide;
ToolBar.Free;
ToolBar := nil;
Form1.Show;
end;
end;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
CoolBar1.AutoSize := True;
ToolBar := TToolBar.Create(nil);
ToolBar.Parent := CoolBar1;
ToolBar.ShowCaptions := True;
ToolBar.AutoSize := True;
TBtn := TToolButton.Create(nil);
TBtn.Parent := ToolBar;
TBtn.Name := 'Btn1';
TBtn.Caption := 'Test1';
TBtn.OnClick := ToolBarClick;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
ToolBar.Free;
end;
end.