?
Solved

create buttons during runtime

Posted on 2001-09-09
3
Medium Priority
?
149 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 400 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

771 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