Solved

Set new component name

Posted on 2002-03-04
4
192 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: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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
calling procedure inside activexForm from secondform 1 232
Print Graphic and Text to Epson TM-T88v 12 176
select query - oracle 16 92
CheckListBox usage 3 50
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

20 Experts available now in Live!

Get 1:1 Help Now