I posted this earlier, but deleted it cause i thought i could contribute more, but soon realized i could not. Anyways, I need to create tabs, groups and actionitems at runtime.
procedure TfrmMain.Button2Click(Sender: TObject);
var
Tab: TRibbonTabItem;
Group: TRibbonGroup;
//Item: TActionItem;
begin
Tab:= Ribbon1.Tabs.Add;
Tab.Caption:= 'Test';
Group:= TRibbonGroup.Create(Tab.Page);
//Tab.Page.AddGroup(Group);
Group.Caption:= 'Test Group';
//create actionitem on group
end;
Any help would be greatly appreciated. I cant seen to find any good resource showing how to accomplish this at runtime
All the tabs and groups for each tab seem to be created without any issues. I cant seem to get the buttons to create correctly. Below is the code for the buttons to be created on each group. I have a show message that I look at for the number of buttons before it goes into this for loop and the number is always correct. Yet, only one button seems to be displayed on the group.
//ShowMessage(IntToStr(ButtonNames.Count));
for K:= 0 to ButtonNames.Count-1 do
begin
BarItem := ActionManager1.ActionBars.Add;
BarItem.ActionBar := RGroup;
BarAction := BarItem.Items.Add;
BarAction.Caption := ButtonNames[K];
end; //for K:= 0 to ButtonNames.Count-1 do
Below is the entire source code for the creation of the entire set of tabs, groups, and buttons
procedure TfrmMain.Button1Click(Sender: TObject);
var
I, J, K: Integer;
JSONData, TabNames, GroupNames, ButtonNames: TStringList;
NavData: TJSONObject;
Tabs, Groups, Buttons, Tab, Group, Button: TJSONValue;
TabItem: TRibbonTabItem;
RGroup: TRibbonGroup;
BarItem: TActionBarItem;
BarAction: TActionClientItem;
begin
JSONData:= TStringList.Create;
if openDialog1.Execute then
begin
JSONData.LoadFromFile(openDialog1.FileName);
try
NavData:= getJSONObj(JSONData.Text);
if NavData <> nil then
begin
{Ribbon1:= TRibbon.Create(self);
Ribbon1.Parent:= Self;
ActionManager1:= TActionManager.Create(self);
Ribbon1.ActionManager:= ActionManager1;}
Tabs:= getTabs(NavData);
TabNames:= TStringList.Create;
getTabNames(Tabs, TabNames);
for I:= 0 to TabNames.Count-1 do
begin
TabItem := Ribbon1.Tabs.Add;
TabItem.Caption := TabNames[I];
Tab:= getTabByName(Tabs, TabNames[I]);
Groups:= getGroups(TJSonObject(Tab));
GroupNames:= TStringList.Create;
getGroupNames(Groups, GroupNames);
for J:= 0 to GroupNames.Count-1 do
begin
RGroup := TRibbonGroup.Create(Ribbon1);
RGroup.Parent := TabItem.Page;
RGroup.Caption := GroupNames[J];
Group:= getGroupByName(Groups, GroupNames[J]);
Buttons:= getButtons(TJSonObject(Group));
ButtonNames:= TStringList.Create;
getButtonNames(Buttons, ButtonNames);
//ShowMessage(IntToStr(ButtonNames.Count));
for K:= 0 to ButtonNames.Count-1 do
begin
BarItem := ActionManager1.ActionBars.Add;
BarItem.ActionBar := RGroup;
BarAction := BarItem.Items.Add;
BarAction.Caption := ButtonNames[K];
end; //for K:= 0 to ButtonNames.Count-1 do
ButtonNames.Free;
end; //for J:= 0 to GroupNames.Count-1 do
GroupNames.Free;
end;
TabNames.Free;
end;
finally
NavData.Free;
end;
end;
JSONData.free;
end;