Ver Mensaje Individual
  #2  
Antiguo 30-01-2013
cd.rafael cd.rafael is offline
Miembro
 
Registrado: abr 2012
Posts: 59
Reputación: 13
cd.rafael Va por buen camino
Cordial Saludo,

Logré realizar el armado del Menú Ribbon, pero ahora tengo problemas de Access Violation cuando cierro el form (MDICHILD). A continuación pongo el código para ver si alguien me puede indicar en dónde estoy cometiendo un error. Cabe anotar que en el evento close del formulario libero los objetos.

Los objeto globales son:

Código:
crpOpPagina: TCustomRibbonPage;
rtiOpTab:    TRibbonTabItem;
rgpOpciones: array of TRibbonGroup;
aclOpLista:  TActionList;
actOpciones: array of TAction;
Código:
var
    mniMenu:  TMenuItem;
    i, j:     integer;
    lBlItems: Boolean;
begin
    //Creación del ActionList
    aclOpLista := TActionList.Create(self);
    aclOpLista.Name := 'OpcionesForma';

    //Crear Página (TAB) Ribbon
    with FrmPrincipal.Ribbon1.Tabs.Add do
    begin
        Caption := 'Opciones Forma';
        KeyTip := 'OpcionesForma';
    end;

    crpOpPagina := FrmPrincipal.Ribbon1.Tabs[FrmPrincipal.Ribbon1.Tabs.Count - 1].Page;

    //Crear Grupos Ribbon
    for i := 0 to ComponentCount - 1 do
    begin
        if (Components[i].ClassName = 'TMenuItem') then
        begin
            if (TMenuItem(Components[i]).Caption <> '-') then
            begin
                if (Length(Trim(TMenuItem(Components[i]).Parent.Caption)) = 0) then
                begin
                    SetLength(rgpOpciones, Length(rgpOpciones) + 1);
                    rgpOpciones[Length(rgpOpciones)] := TRibbonGroup.Create(crpOpPagina.Parent);
                    rgpOpciones[Length(rgpOpciones)].Caption := TMenuItem(Components[i]).Caption;
                    rgpOpciones[Length(rgpOpciones)].Parent := crpOpPagina;
                    rgpOpciones[Length(rgpOpciones)].ActionManager := FrmPrincipal.MnuPrincipal;
                    rgpOpciones[Length(rgpOpciones)].KeyTip := TMenuItem(Components[i]).Caption;
                    rgpOpciones[Length(rgpOpciones)].Enabled := true;
                    rgpOpciones[Length(rgpOpciones)].Rows := 2;
                    rgpOpciones[Length(rgpOpciones)].GroupAlign := gaVertical;
                    with FrmPrincipal.MnuPrincipal.ActionBars.Add do
                    begin
                        lBlItems := False;
                        ActionBar := rgpOpciones[Length(rgpOpciones)];
                        //Crear las Opciones para cada grupo
                        for j := 0 to ComponentCount - 1 do
                        begin
                            if (Components[j].ClassName = 'TMenuItem') then
                            begin
                                mniMenu := TMenuItem(Components[j]);
                                while (Length(Trim(mniMenu.Parent.Caption)) > 0) do
                                begin
                                    if (mniMenu.Parent.Caption = TMenuItem(Components[i]).Caption) then
                                    begin
                                        SetLength(actOpciones, Length(actOpciones) + 1);
                                        actOpciones[Length(actOpciones)] := TAction.Create(aclOpLista);
                                        actOpciones[Length(actOpciones)].Name := mniMenu.Name;
                                        actOpciones[Length(actOpciones)].OnExecute := mniMenu.OnClick;
                                        with Items.Add do
                                        begin
                                        Action := actOpciones[Length(actOpciones)];
                                        KeyTip := mniMenu.Caption;
                                        Caption := mniMenu.Caption;
                                        CommandStyle := csButton;
                                        (CommandProperties as TButtonProperties).ButtonSize := bsLarge;
                                        ImageIndex := 49;
                                        Enabled := mniMenu.Enabled;
                                        end;
                                        lBlItems := true;
                                    end;
                                    mniMenu := mniMenu.Parent;
                                end;
                            end;
                        end; //--for j := 0 to ComponentCount - 1 do
                        if (not lBlItems) then
                        begin
                            mniMenu := TMenuItem(Components[i]);
                            SetLength(actOpciones, Length(actOpciones) + 1);
                            actOpciones[Length(actOpciones)] := TAction.Create(aclOpLista);
                            actOpciones[Length(actOpciones)].Name := mniMenu.Name;
                            actOpciones[Length(actOpciones)].OnExecute := mniMenu.OnClick;
                            with Items.Add do
                            begin
                                Action := actOpciones[Length(actOpciones)];
                                KeyTip := mniMenu.Caption;
                                Caption := mniMenu.Caption;
                                CommandStyle := csButton;
                                (CommandProperties as TButtonProperties).ButtonSize := bsLarge;
                                ImageIndex := 49;
                                Enabled := mniMenu.Enabled;
                            end;
                        end;
                    end; //--with FrmPrincipal.MnuPrincipal.ActionBars.Add do
                end;
            end;
        end;
    end;
    //
    crpOpPagina.Refresh;
    crpOpPagina.SetFocus;
end;
Muchas gracias.
Responder Con Cita