Solved

create buttons during runtime

Posted on 2001-09-09
3
148 Views
Last Modified: 2010-04-06
hi! i want to create some buttons (the count of the buttons is unknown) during runtime. when you klick them an shellexecute command shall be executed with a button specific file. how can i do that ?
0
Comment
Question by:ItsMe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
lucika earned 100 total points
ID: 6468414
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  PListButtonRec=^TListButtonRec;
  TListButtonRec=record
    tag: integer;
    Button: TButton;
    MyCommand: String;
  end;

  TForm1 = class(TForm)
    AddButton: TButton;
    Edit1: TEdit;
    DelButton: TButton;
    procedure AddButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure MyButtonClick(Sender: TObject);
    procedure DelButtonClick(Sender: TObject);

  private
    ListButton: TList;
    MaxTag: integer;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.MyButtonClick(Sender: TObject);
var i: integer;
begin
  for i:=0 to ListButton.Count-1 do
    if PListButtonRec(ListButton.Items[i])^.tag=(Sender as TWinControl).Tag then
    begin
      ShowMessage(PListButtonRec(ListButton.Items[i])^.MyCommand);
      exit;
    end;
end;

procedure TForm1.AddButtonClick(Sender: TObject);
var
  tmButton: PListButtonRec;
begin
  new(tmButton);
  inc(MaxTag);

  tmButton^.tag:=MaxTag;
  tmButton^.MyCommand:='Run command ('+inttostr(MAxTag)+')';

  tmButton^.Button:=TButton.Create(self);
  tmButton^.Button.Parent:=self;
  tmButton^.Button.Left:=MaxTag*100;
  tmButton^.Button.Caption:='#'+inttostr(MAxTag);
  tmButton^.Button.Tag:=MaxTag;
  tmButton^.Button.OnClick:=MyButtonClick;

  ListButton.Add(tmButton);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ListButton:=TList.Create;
  Maxtag:=0;
end;

procedure TForm1.FormDestroy(Sender: TObject);
var i: integer;
begin
  for i:=0 to ListButton.Count-1 do
    Dispose(PListButtonRec(ListButton.Items[i]));
  ListButton.Destroy;
end;


procedure TForm1.DelButtonClick(Sender: TObject);
var i: integer;
    tmButton: PListButtonRec;
    mtag: integer;
begin
  try
  mtag:=StrToInt(Edit1.text);
  for i:=0 to ListButton.Count-1 do
    if PListButtonRec(ListButton.Items[i])^.tag=mTag then
    begin
      tmButton:=PListButtonRec(ListButton.Items[i]);
      tmButton^.Button.Destroy;
      Dispose(tmButton);
      ListButton.Delete(i);
      exit;
    end;
  except
      showmessage('Error');
  end;
end;

end.
0
 

Author Comment

by:ItsMe
ID: 6468482
hi lucika!
i don't get it to work within my app (The declaration of myButtonClick fails). please send me the whole project file to philipl@web.de

thanks a lot !

kind regards
ItsMe
0
 

Author Comment

by:ItsMe
ID: 6468537
thank you! mail arrived ;-)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question