Solved

Set new component name

Posted on 2002-03-04
4
189 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
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:mnasman
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 300 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now