Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Problem about objects

In VB we can create any amount of objects(same type ) using the same name.So each object gets its index number and all the objects uses the same code.In delphi how can i do that.Thanx

Comments

  • zibadianzibadian Member Posts: 6,349
    : In VB we can create any amount of objects(same type ) using the same name.So each object gets its index number and all the objects uses the same code.In delphi how can i do that.Thanx
    :
    In Delphi you can create either arrays of object or use a TList to hold objects. In case of components, the names still need to be unique or not given. Here is an example, which creates 5 new TEdits on a form:
    [code]
    procedure TForm1.Button1Click(Sender: TObject);
    var
    i: integer;
    begin
    for i := 1 to 5 do
    with TEdit.Create(Self) do
    begin
    Name := 'ExampleEdit'+IntToStr(i);
    Parent := Self;
    Left := 8;
    Top := (i-1)*24+8;
    Text := Name;
    end;
    end;
    [/code]
    You can then access the edit using the FindComponent() method:
    [code]
    var
    E: TEdit;
    begin
    E := FindComponent('ExampleEdit2') as TEdit;
    E.Text := 'New Value';
    end;
    [/code]

Sign In or Register to comment.