'deleting specific items from TGrid

`

procedure TfrmFinal.providerBtnClick(Sender: Tobject); 
var
  provider,text: String;
  J: Integer;
  airtimeBtn: TCornerButton;
  products: TJSONArray;
begin
  glPosScreen.DeleteChildren; 
  posScreen.Visible := True;
  tcMain.Visible := False;
  provider := (sender as TCornerButton).Text;
  case frmDataModule.stringIndex(provider,['MTN','VODACOM','CELL C','TELKOM','RINGAS','EASYLOAD'],false) of 
    0:begin                              
      networks := jsonObject.GetValue<TJSONArray>('networks');y
        begin
          products := networks[0].GetValue<TJSONArray>('products') as TJSONArray;at networks position 0
        for j := 0 to products.Count-1 do 
          begin
            text := ansiUppercase(products[J].GetValue<String>
            airtimeBtn := TCornerButton.Create(glPosScreen);
            airtimeBtn.Parent := glPosScreen;
            airtimeBtn.Text := text;
            airtimeBtn.TextSettings.WordWrap := True;
            airtimeBtn.StyleLookup := 'mtnAirtimeBtn';
            airtimeBtn.OnClick := airtimeBtnClick;
            case j mod 3 of                    
            0: addMargins(airtimeBtn,5,2.5,0,5);
            1: addMargins(airtimeBtn,5,2.5,0,2.5);
            2: addMargins(airtimeBtn,5,5,0,2.5);
            end;
          end;
        end;
      end;
    1:begin
      networks := jsonObject.GetValue<TJSONArray>('networks');
        begin
          products := networks[1].GetValue<TJSONArray>('products') as TJSONArray;
          for J := 0 to products.Count-1 do
            begin
              text := ansiUppercase(products[J].GetValue<String>
              airtimeBtn := TCornerButton.Create(glPosScreen);                         
              airtimeBtn.Parent := glPosScreen;
              airtimeBtn.Text := text;
              airtimeBtn.TextSettings.WordWrap := True;
              airtimeBtn.StyleLookup := 'vodacomAirtimeBtn';
              airtimeBtn.OnClick := airtimeBtnClick;
              case j mod 3 of
                0: addMargins(airtimeBtn,5,2.5,0,5);
                1: addMargins(airtimeBtn,5,2.5,0,2.5);
                2: addMargins(airtimeBtn,5,5,0,2.5);
              end;
            end;
        end;
      end;
    2:begin
      networks := jsonObject.GetValue<TJSONArray>('networks');
        begin
          products := networks[2].GetValue<TJSONArray>('products') as TJSONArray;
          for J := 0 to products.Count-1 do
            begin
              text := ansiUppercase(products[J].GetValue<String>
              airtimeBtn := TCornerButton.Create(glPosScreen);
              airtimeBtn.Parent := glPosScreen;
              airtimeBtn.Text := text;                                            
              airtimeBtn.TextSettings.WordWrap := True;
              airtimeBtn.StyleLookup := 'cellCAirtimeBtn';
              airtimeBtn.OnClick := airtimeBtnClick;
              case j mod 3 of
                0: addMargins(airtimeBtn,5,2.5,0,5);
                1: addMargins(airtimeBtn,5,2.5,0,2.5);
                2: addMargins(airtimeBtn,5,5,0,2.5);
              end
            end;
        end;
      end;
    3:begin
      networks := jsonObject.GetValue<TJSONArray>('networks');
        begin
          products := networks[3].GetValue<TJSONArray>('products') as TJSONArray;
          for J := 0 to products.Count-1 do
            begin
              text := ansiUppercase(products[J].GetValue<String>
              airtimeBtn := TCornerButton.Create(glPosScreen);
              airtimeBtn.Parent := glPosScreen;
              airtimeBtn.Text := text;
              airtimeBtn.TextSettings.WordWrap := True;                          
              airtimeBtn.StyleLookup := 'telkomAirtimeBtn';
              airtimeBtn.OnClick := airtimeBtnClick;
              case j mod 3 of
                0: addMargins(airtimeBtn,5,2.5,0,5);
                1: addMargins(airtimeBtn,5,2.5,0,2.5);
                2: addMargins(airtimeBtn,5,5,0,2.5);
              end
            end;
        end;
      end;
    4:begin
      networks := jsonObject.GetValue<TJSONArray>('networks');
        begin
          products := networks[4].GetValue<TJSONArray>('products') as TJSONArray;
          for J := 0 to products.Count-1 do
            begin
              text := ansiUppercase(products[J].GetValue<String>
              airtimeBtn := TCornerButton.Create(glPosScreen);
              airtimeBtn.Parent := glPosScreen;
              airtimeBtn.Text := text;                                           
              airtimeBtn.TextSettings.WordWrap := True;
              airtimeBtn.StyleLookup := 'ringasAirtimeBtn';
              airtimeBtn.OnClick := airtimeBtnClick;
              case j mod 3 of
                0: addMargins(airtimeBtn,5,2.5,0,5);
                1: addMargins(airtimeBtn,5,2.5,0,2.5);
                2: addMargins(airtimeBtn,5,5,0,2.5);
              end
            end;
        end;
      end;
    5:begin
      networks := jsonObject.GetValue<TJSONArray>('networks');
        begin
        products := networks[5].GetValue<TJSONArray>('products') as TJSONArray;
        for J := 0 to products.Count-1 do
          begin
            text := ansiUppercase(products[J].GetValue<String>
            airtimeBtn := TCornerButton.Create(glPosScreen);                      
            airtimeBtn.Parent := glPosScreen;
            airtimeBtn.Text := text;
            airtimeBtn.TextSettings.WordWrap := True;
            airtimeBtn.StyleLookup := 'easyLoadAirtimeBtn';
            airtimeBtn.OnClick := airtimeBtnClick;
            case j mod 3 of
              0: addMargins(airtimeBtn,5,2.5,0,5);
              1: addMargins(airtimeBtn,5,2.5,0,2.5);
              2: addMargins(airtimeBtn,5,5,0,2.5);
            end
          end;
        end;
      end;
  end;
end;

`enter image description here

I have a TGrid in my application. and I have a function which adds default buttons to the grid every time the user navigates to a specific screen. Each time the user clicks to go to the specified screen the default buttons are added again. I got around this by deleting children before I add the default BTNS. How would I only delete the default buttons and keep the rest of the buttons there? (When a user selects a product it populates the grid with the various items for said product and every time I go back to the screen with the grid it is supposed to still have the previous products buttons so the user can easily navigate back to the POS screen and still have the available products there)

procedure TfrmFinal.posClick(Sender: TObject); 
    begin
          glPosScreen.DeleteChildren;
          addDefaultBtns;
          tcMain.Visible := false;
          posScreen.Visible := true;
   end;


Solution 1:[1]

As far as I understand your problem, your question is about the buttons you have on the lower part of your screen, in the scrollable area. That is the green buttons labeled "Back", "Main Menu" and "Process", and the yellow buttons labeled "R2 MTN", "R5 MTN", "R10 MTN" ....

When you call glPosScreen.DeleteChildren; all those buttons are deleted, and so you call addDefaultButtons; to add back the three green buttons. The problem then is that all those yellow buttons remain missing.

Correction 1: Don't call DeleteChildren as you dont want to delete them all.

Correction 2: Don't call addDefaultButtons as you already have the three green buttons.

Correction 3: If you need to do changes to the three green buttons, deal with them one by one.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tom Brunberg