Ver Mensaje Individual
  #4  
Antiguo 12-04-2015
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola JuniorSoft.

La idea que te propongo es agrupar la creación del MDIChild y del ToolButton correspondiente como hago en este ejemplo simplificado, que usa un TToolBar un TPanel (alBottom) y dentro de él tres TButton.
Código Delphi [-]
type
  TfrmMain = class(TForm)
  ... 
  private
    FChildTags: Integer;
    procedure OpenMDIChild(AClass: TFormClass; const btnCaption: string; aAction: TAction );
  public
    property ChildTag: Integer read FChildTags;
    procedure DeleteToolButton(const TagButton: Integer);
  end;
...
implementation
uses Unit2, Unit3, Unit4; // MDIChilds

procedure TfrmMain.FormCreate(Sender: TObject);
begin
  FChildTags := 1; // p
end;


// Crear-Mostrar MDIChilds
procedure TfrmMain.OpenMDIChild(AClass: TFormClass; const btnCaption: string; aAction: TAction);
var
  i, inx: Integer;
  nb: TToolButton;
begin
  for i:= MDIChildCount-1 downto 0 do
    if MDIChildren[i] is AClass then
    begin
      if MDIChildren[i].WindowState = wsMinimized then
        MDIChildren[i].WindowState:= wsNormal;
      MDIChildren[i].BringToFront;
      Exit;
    end;

  with AClass.Create(Self) do
  begin
    Tag           := FChildTags;
    nb            := TToolButton.Create(ToolBar1);
    nb.Height     := ImageList1.Height;
    nb.Width      := ImageList1.Width;
    nb.Caption    := btnCaption;
    inx           := ToolBar1.ButtonCount - 1;
    if inx > -1 then
      nb.Left := ToolBar1.Buttons[inx].Left + ToolBar1.Buttons[inx].Width
    else
      nb.Left := 0;
    nb.Action := aAction;
    nb.Parent := ToolBar1;
    nb.Tag    := ChildTag;
    //...
    Inc(FChildTags);
  end;
end;

// Eliminar ToolButton
procedure TfrmMain.DeleteToolButton(const TagButton: Integer);
var
  i: Integer;
begin
  for i:= ToolBar1.ButtonCount-1 downto 0 do
    if ToolBar1.Buttons[i].Tag = TagButton then
      ToolBar1.Buttons[i].Free;
end;

// Llamada crear-mostrar MDIChilds
procedure TfrmMain.btnChild1Click(Sender: TObject);
begin
  OpenMDIChild(TChild1, 'Child1', TAction(ActionList1.Actions[0]));
end;

procedure TfrmMain.btnChild2Click(Sender: TObject);
begin
  OpenMDIChild(TChild2, 'Child2', TAction(ActionList1.Actions[1]));
end;

procedure TfrmMain.btnChild3Click(Sender: TObject);
begin
  OpenMDIChild(TChild3, 'Child3', TAction(ActionList1.Actions[2]));
end;

// Acciones de ejemplo
procedure TfrmMain.Action1Execute(Sender: TObject);
begin
  ShowMessage(TToolButton(Sender).Name);
end;

procedure TfrmMain.Action2Execute(Sender: TObject);
begin
  ShowMessage(TToolButton(Sender).Name);
end;

procedure TfrmMain.Action3Execute(Sender: TObject);
begin
  ShowMessage(TToolButton(Sender).Name);
end;
...

Salida:


Como verás es sólo un ejemplo orientativo, si nos explicas mas detalladamente la situación, tal vez lo podamos ajustar.

Saludos

Pd: Te ajunto los archivos fuentes de la prueba.
Archivos Adjuntos
Tipo de Archivo: zip junior.zip (14,4 KB, 5 visitas)
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita