How to reference the goal property created with 'with TEdit.Create (Self)'?

1

How to reference ownership of a goal created with with TEdit.Create(Self) , and will it be used in another object that is also being created as with TSpeedButton.Create(Self) ?

Follow the code:

with TEdit.Create(Self) do
begin
  Name   := 'ed'+IntToStr(i);
  Parent := Self;
  Top    := 0;
  Left   := 0;
  Width  := 50;

  with TSpeedButton.Create(Self) do
  begin
    Name   := 'sb'+IntToStr(i);
    Parent := Self;
    Top    := 0;
    //Left := TEdit().Left + TEdit().Width; //Como referenciar o TEdit?
    Width  := 20;
  end;
end;
    
asked by anonymous 28.10.2017 / 16:22

1 answer

4

I do not see the need to cascade the creation of the component, but anyway you reference using the component name you created:

with TEdit.Create(Self) do
begin
  Name   := 'ed'+IntToStr(i);
  Parent := Self;
  Top    := 0;
  Left   := 0;
  Width  := 50;

  with TSpeedButton.Create(Self) do
  begin
    Name   := 'sb'+IntToStr(i);
    Parent := Self;
    Top    := 0;
    Left := TEdit('ed'+IntToStr(i)).Left + TEdit('ed'+IntToStr(i)).Width; 
    Width  := 20;
  end;
end;

I would do separate, each in your code block:

with TEdit.Create(Self) do
begin
  Name   := 'ed'+IntToStr(i);
  Parent := Self;
  Top    := 0;
  Left   := 0;
  Width  := 50;
end;

with TSpeedButton.Create(Self) do
begin
  Name   := 'sb'+IntToStr(i);
  Parent := Self;
  Top    := 0;
  Left := TEdit('ed'+IntToStr(i)).Left + TEdit('ed'+IntToStr(i)).Width; 
  Width  := 20;
end;

And the correct one would still be to create Variables for each component, this way it gets more organized and easy to locate the components.

var
  vEdtUsuario : TEdit;
  vBtn_Ok     : TSpeedButton;
    
30.10.2017 / 11:15