Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Set new component name

Posted on 2002-03-04
4
Medium Priority
?
203 Views
Last Modified: 2010-04-04
Set new component name

How to set new component name wich is put in Tcomponentlist and must be different then others ?

Thanks.
0
Comment
Question by:ghjlk
[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
4 Comments
 
LVL 2

Expert Comment

by:DelphiArchitect
ID: 6840525
I'm not certain what you are asking, could you please clarify.  Are you talking about finding component names for components that are created at runtime?  If so, what type of components and what is creating them?

Thanks,
Delphi Architect
James Higgins
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6840953
Hello

  you can choose any name as component, but sure you can't use one of the existing component, try to put a prefix for your components, like TGHButton, or whatever
0
 

Author Comment

by:ghjlk
ID: 6841247
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    AComponentList : TComponentList;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
AComponentList:=TComponentList.Create;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
AComponentList.Add(TButton.Create(Self));
//TButton(AComponentList[0]).Name:='Button1'; // NOT BY THIS WAY  !!!!!
TButton(AComponentList[0]).Parent:=Form1;
AComponentList.Add(TButton.Create(Self));
//TButton(AComponentList[1]).Name:='Button2'; // NOT BY THIS WAY  !!!!!
TButton(AComponentList[1]).Parent:=Form1;
end;

end.
0
 
LVL 2

Accepted Solution

by:
vbmn earned 1200 total points
ID: 6842378
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit3: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    cni:integer;
    cns:string;
    clc:integer;
    acomponentlist : TComponentList;
    procedure SetComponentName(componentindex:integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SetComponentName(componentindex:integer);
begin
cni:=0;
clc:=0;
while clc<acomponentlist.count do
begin
cns:='';
if TObject(aComponentlist[clc]) is TEdit then
if TObject(aComponentlist[componentindex]) is TEdit then
begin
cni:=cni+1;
try
 TEdit(aComponentlist[componentindex]).Name:='Edit'+inttostr(cni);
 except
 cns:='Out';
end;
if cns='' then exit;
end;
inc(clc);
end;
cni:=cni+1;
if TObject(aComponentlist[componentindex]) is TEdit then
TEdit(aComponentlist[componentindex]).Name:='Edit'+inttostr(cni);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to 19 do
  begin
    acomponentlist.Add(TEdit.Create(Self));
    setcomponentname(i);
    with TEdit(acomponentlist[i]) do
    begin
      Left := 10;
      Top := i * 20;
      Parent := self;
    end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
acomponentlist:=tcomponentlist.Create;
end;

end.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

609 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