Board index » delphi » Find a component by name

Find a component by name

On runtime, can I do anything like this:

With TObject.Name('B'+IntToStr(1)) as tSpeedButton do
begin
..
end;

Or can I scan to find it?

thanks.

--
Sten Karsten Vartdal
stenvart-remo...@online.no
http://home.sol.no/~stenvart/

Maintainer of Delphi Help Page
http://home.sol.no/~stenvart/delphi.html

 

Re:Find a component by name


i think you have to use

try
    with TSpeedbutton(Form1.FindComponent('B1')) do begin
    (...)
    end;
except
end;

when Form1 is the Owner of the Speedbutton

--
Andreas Klein
eMail: a-k...@metronet.de

Sten Karsten Vartdal schrieb in Nachricht <6jsc2a$f2...@o.online.no>...
On runtime, can I do anything like this:

With TObject.Name('B'+IntToStr(1)) as tSpeedButton do
begin
..
end;

Or can I scan to find it?

thanks.

--
Sten Karsten Vartdal
stenvart-remo...@online.no
http://home.sol.no/~stenvart/

Maintainer of Delphi Help Page
http://home.sol.no/~stenvart/delphi.html

Re:Find a component by name


The object of your question in nearly perfect ;-)

function FindComponent(const AName: string): TComponent;

should do the thing

Quote

Re:Find a component by name


Try using the FindComponent() function. Something like this:

var
  I: Integer;
begin
for I := 1 to 3 do
  with FindComponent('Edit' + IntToStr(I)) as TEdit do
  begin
    Text := 'Test';
  end;
end;

or:

var
  I: Integer;
begin
for I := 1 to 3 do
  with TEdit(FindComponent('Edit' + IntToStr(I))) do
  begin
    Text := 'Test';
  end;
end;

Hope this helps!
--

Rodney E Geraghty
GERA-Tech
Ottawa, Canada
gera...@ibm.net

Sten Karsten Vartdal <stenv...@online.no> wrote in article
<6jsc2a$f2...@o.online.no>...
On runtime, can I do anything like this:

With TObject.Name('B'+IntToStr(1)) as tSpeedButton do
begin
..
end;

Or can I scan to find it?

thanks.

--
Sten Karsten Vartdal
stenvart-remo...@online.no
http://home.sol.no/~stenvart/

Maintainer of Delphi Help Page
http://home.sol.no/~stenvart/delphi.html

----------

Re:Find a component by name


Try FindComponent

Quote
Sten Karsten Vartdal wrote:

> On runtime, can I do anything like this:

> With TObject.Name('B'+IntToStr(1)) as tSpeedButton do
> begin
> ..
> end;

> Or can I scan to find it?

> thanks.

> --
> Sten Karsten Vartdal
> stenvart-remo...@online.no
> http://home.sol.no/~stenvart/

> Maintainer of Delphi Help Page
> http://home.sol.no/~stenvart/delphi.html

--
Bruce Swart (br...@cm.co.za)
Systems Analyst

27-(0)31-3325541 (W)
27-(0)31-3325552 (F)

Computer Management (Pty) Ltd
85 Smith Street
Durban
South Africa
4001

Other Threads