Solved

Set new component name

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

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 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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

735 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