I currently create a two TLabels and a TEdit dynamically, naming them LblDesc+i, EdtAmount+i and LblUnit+i - Where i is an integer that I iterate up by one each time I add those 3 elements. The data in the elements are just for simulation purposes. My problem now is deleting the three objects. Ive tried with free and FreeAndNil, no luck at all. Any help is greatly appreciated.
procedure TForm1.BtnAddClick(Sender: TObject);
begin
LblDesc := TLabel.Create(Self);
LblDesc.Caption := 'Item '+IntToStr(i);
LblDesc.Name := 'LblDesc'+IntToStr(i);
LblDesc.Left := 16;
LblDesc.Top := 30 + i*30;
LblDesc.Width := 100;
LblDesc.Height := 25;
LblDesc.Parent := Self;
EdtAmount := TEdit.Create(Self);
EdtAmount.Text := IntToStr(i);
EdtAmount.Name := 'EdtAmount'+IntToStr(i);
EdtAmount.Left := 105;
EdtAmount.Top := 27 + i*30;
EdtAmount.Width := 60;
EdtAmount.Height := 25;
EdtAmount.Parent := Self;
LblUnit := TLabel.Create(Self);
LblUnit.Caption := 'Kg';
LblUnit.Name := 'LblUnit'+IntToStr(i);
LblUnit.Left := 170;
LblUnit.Top := 30 + i*30;
LblUnit.Width := 50;
LblUnit.Height := 25;
LblUnit.Parent := Self;
i := i+1;
end;
procedure TForm1.BtnRemoveClick(Sender: TObject);
begin
//Delete
end;