Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert a speedbutton

Status
Not open for further replies.

filipe26

Programmer
Mar 17, 2003
152
PT
how to insert a speedbutton in a toolbar in runtime?

I have the following code but i cant do it.

botao:=Tspeedbutton.Create(main.ToolBar1);
botao.Left:=0;
botao.Top := 2;
botao.Width := 81;
botao.Height := 47;
botao.Caption :=htmlchecklist1.Items.Text;

Thanks
 
Try adding this:

botao.Parent:= main.ToolBar1;
application.processmessages;

The Create sets the Owner, but not the Parent. The Parent property is actually what determines where the button will appear.

-Dell
 
and if i wanted to free a certain speedbutton that was created on runtime,how do i do that?
 
Code:
"Process messages" waht it does?

You tell windows to "process messages". Let windows do all normal painting and all other system messages.


Code:
and if i wanted to free a certain speedbutton that was created on runtime,how do i do that?

Code:
botao.Free;



//Nordlund
 
i have the following code but not enter in the if clause:

for x := main.ToolBar1.ComponentCount - 1 downto 0 do
begin
Temp := Components[x];
if (Temp is Tspeedbutton) then
begin
RemoveComponent(Temp);
end;
end;
 
Nordlund,

I'm not trying to criticise you but there is a quote tag you can use when quoting other people:
[ignore]
Nordlund said:
You tell windows to "process messages"
[/ignore]
and the result looks like this:
Nordlund said:
You tell windows to "process messages"

For more information on all the tags you can use, click the "Process TGML" link (above the "Submit Post" button at the bottom of the page).

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
If you put a break point on the fourth line
Code:
if (Temp is Tspeedbutton) then
What is Temp equal to when you hover over it at runtime?

Also, add a Watch or MessageDlg to output Temp.Name and see whether it outputs what you're expecting.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
You haven't said what you're trying to do. If you want to delete the TSpeedButton completely from the application then use this:
Code:
var
  x: Integer;
  Temp: TComponent;
begin
  for x := ToolBar1.ComponentCount - 1 downto 0 do
    if Toolbar1.Components[x] is TSpeedButton then
    begin
       Temp := Toolbar1.Components[x];
       Temp.Free;
    end;
end;

If you simply want to move the component to a different parent then use something like this:
Code:
var
  x: Integer;
  Temp: TComponent;
begin
  for x := ToolBar1.ComponentCount - 1 downto 0 do
    if Toolbar1.Components[x] is TSpeedButton then
    begin
       Temp := Toolbar1.Components[x];
       (Temp as TSpeedButton).Parent := GroupBox1;
       // exchange GroupBox1 for the appropriate parent control
    end;
end;

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
try this

Code:
var
  x: integer;
  Temp: TControl;
begin
  for x := main.ToolBar1.ControlCount - 1 downto 0 do
  begin
    Temp := main.ToolBar1.Controls[x];
    if (Temp is Tspeedbutton) then
      RemoveComponent(Temp);
  end;
end;

Use ControlCount and Controls property of Toolbar, not ComponentCount and Component. It's simply because SpeedButton is a Control not a Component (although it is the descendant of TComponent).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top