Jump to content

Mobile TreeMenu Add Items At Runtime (parent and children)


andyhill

Recommended Posts

I maintain an array of TreeMenu Items and create TreeMenu Nodes at runtime from this master list.

Please show me how to Create Parent Node (with no children) and Parent Node with Children Node - thanks.

           for i:= 0 to Length(UniMainModule.MyTreeMenuItems)-1 do begin
             case i of
                     // Parent (no children)
               0..2: begin
                       SystemMenu.Items.Add(UniMainModule.MyTreeMenuItems.Name);
                     end;
               3..4: begin
                       SystemMenu.Items.Add(UniMainModule.MyTreeMenuItems.Name);
                     end;
               5..8: begin
                       SystemMenu.Items.Add(UniMainModule.MyTreeMenuItems.Name);
                     end;
                  9: begin
                       SystemMenu.Items.Add(UniMainModule.MyTreeMenuItems.Name);
                     end;

                     // Parent (with children)
              10: begin
                       SystemMenu.Items.Add(UniMainModule.MyTreeMenuItems.Name);
                     end;
                     // Child
             11..14: begin
                       SystemMenu.Items.AddChild(10, UniMainModule.MyTreeMenuItems.Name);
                     end;

 

...

 

 

Link to comment
Share on other sites

On 3/10/2019 at 5:03 AM, andyhill said:

Please show me how to Create Parent Node (with no children) and Parent Node with Children Node - thanks.

Hello,

procedure TMainmForm.UnimBitBtn1Click(Sender: TObject);
var
  pNode: TUniTreeNode;
begin
  pNode := UnimTreeMenu1.Items.Add(nil, 'Parent');
  UnimTreeMenu1.Items.AddChild(pNode, 'Child')
end;

 

Link to comment
Share on other sites

My code AV's at runtime, please advise - thanks.

    SystemMenu.BeginUpdate;
    SystemMenu.Items.Clear; // FAILS TO CLEAR TreeMenu !!!
    //SystemMenu.SourceMenu.Items.Clear;
    for i:= 0 to Length(UniMainModule.MyTreeMenuItems)-1 do begin
      // Parent Nodes
      if ( (i < 15) or (i = 19) or (i = 25) or (i = 32) or (i = 39) ) then begin
        pNode:= SystemMenu.Items.Add(nil, 'Parent');
        pNode.Text:= UniMainModule.MyTreeMenuItems.Name;
        pNode.SelectedIndex:= i;
      end;
      // Child Nodes (uses previous pNode eg. i=14=pNode, i=15=cNode)
      if ( ((i > 14) and (i < 19)) or ((i > 19) and (i < 25)) or ((i > 25) and (i < 32)) or ((i > 32) and (i < 39)) ) then begin
        cNode:= SystemMenu.Items.AddChild(pNode, 'Child');
        cNode.Text:= UniMainModule.MyTreeMenuItems.Name;
        cNode.SelectedIndex:= i;
      end;
    end;
    SystemMenu.EndUpdate;
    UniSession.AddJS(MainmForm.SystemMenu.JSName+'.Refresh;');
    UniSession.Synchronize;
 

Above compiles and runs but throws abstract errors. I know it may have something to do with reusing pNode and cNode  objects ???

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...