Solved

Set new component name

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

829 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