如题:如何在工具条中增加按钮,并指定按钮顺序。
如:从数据库中读取记录字段:'button1','button2','button'。要求按钮顺序是button1,button2,button3. 并请教如何动态清除工具条上的按钮。(包括释放按钮)
我用如下程序构建工具按钮,但显示结果是:button3,button2,button1
while not eof do
begin
toolbtn:=TToolButton.Create(Toolbar);
toolbtn.name:=query1.FieldByName('Name');
toolbtn.Caption:=query1.FieldByName('Caption');
toolbtn.parent:=toolbar;
end;
请问应如何改善代码??? 在此先谢了。。
如:从数据库中读取记录字段:'button1','button2','button'。要求按钮顺序是button1,button2,button3. 并请教如何动态清除工具条上的按钮。(包括释放按钮)
我用如下程序构建工具按钮,但显示结果是:button3,button2,button1
while not eof do
begin
toolbtn:=TToolButton.Create(Toolbar);
toolbtn.name:=query1.FieldByName('Name');
toolbtn.Caption:=query1.FieldByName('Caption');
toolbtn.parent:=toolbar;
end;
请问应如何改善代码??? 在此先谢了。。
Form1: TForm1;
myBtns: array[1..3] of TToolButton; //必须是全局变量,不能是局部变量
//否则函数或过程退出时就自动释放了implementation{$R *.dfm}//创建
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
for i:=low(myBtns) to high(myBtns) do
begin
myBtns[i]:=TToolButton.Create(Form1);
myBtns[i].Name:='MyToolButton'+IntToStr(i);
myBtns[i].Parent:=ToolBar1;
end;
end;//释放
procedure TForm1.Button2Click(Sender: TObject);
var
i: Integer;
begin
for i:=low(myBtns) to high(myBtns) do
myBtns[i].Free;
end;