Einzelnen Beitrag anzeigen

Benutzerbild von Union
Union

Registriert seit: 18. Mär 2004
Ort: Luxembourg
3.490 Beiträge
 
Delphi 7 Enterprise
 
#7

Re: TComponentEditor für eigene Actionlist

  Alt 25. Jun 2006, 19:01
Hallo,

ich hab es jetzt selber herausgefunden. Für alle Interessierten hier die Lösungen:

Standardactions
In Delphi sind die Standardactions als eigene Klassen implementiert. Eine Liste aller definierten Standardactions kann man über ActnRes.TStandardActions.ActionsList1 erhalten.

Da ich in dem speziellen Fall erweiterte Actions verwende, benutze ich die Standardactions nicht, denn sonst müsste ich nur dafür jede einzelne Standardactions-Klasse erneut ableiten. Das ist mir aber zu viel Aufwand; es handelt sich um 50 Klassen.

Hier trotzdem mal die Vorgehensweise (Habe mir aber nicht die Mühe eines Treeview gemacht):
Delphi-Quellcode:
procedure TSecActionsEditor.SelectStdAction;
var
   Frm : TForm;
   dmSa : TStandardActions;
   LbSa : TListBox;
   i : integer;
   ASecAction : TSecAction;
begin

   Frm := TForm.Create(Self);
   with Frm do begin
      Caption := 'Standard Actions';

      LbSa := TListBox.Create(frm);
      with LbSa do
      begin
         Parent := Frm;
         Top := 4;
         Left := 4;
         Width := frm.ClientWidth-8;
         Height := frm.Clientheight-24-8;
         Anchors := [aktop, akleft, akright, akbottom];
      end;

      with TButton.Create(frm) do
      begin
         Parent := frm;
         Top := frm.ClientHeight-28;
         Left := 4;
         Anchors := [akLeft, akBottom];
         Caption := '&Ok';
         ModalResult := mrOk;
      end;

      with TButton.Create(frm) do
      begin
         Parent := frm;
         Top := frm.ClientHeight-28;
         Left := 80;
         Anchors := [akLeft, akBottom];
         Caption := '&Cancel';
         ModalResult := mrCancel;
      end;

      dmSa := TStandardActions.Create(frm);
      for i := 0 to dmSa.ActionList1.ActionCount-1 do
      begin
         LbSa.Items.AddObject(TAction(dmSa.ActionList1.Actions[i]).Caption, dmSa.ActionList1.Actions[i]);
      end;

      ShowModal;
      if modalresult = mrOk then
      begin
         ASecAction := TSecAction(TheDesigner.CreateComponent(TSecAction,nil,0,0,0,0));
         ASecAction.ActionList := FSecActionList;
         ASecAction.Category := SNoCategory;
         ASecAction.Assign(TBasicAction(LbSa.Items.Objects[LbSa.ItemIndex]));

         lbActions.Items.Add(ASecAction.Caption);
         lbActions.ItemIndex := FSecActionList.ActionCount-1;
         RefreshActionsList;
         TheDesigner.SelectComponent(ASecAction);
         TheDesigner.Modified;
      end;
      Free;
   end;
end;
Multiselect von Actions im OI
Das Funktioniert über die Designer-Methode SetSelections - man braucht dafür eine SelectionListe. Bei Multiselect erscheint dann im OI die Anzahl der ausgewählten Elemente, die änderbaren Properties "schrumpfen".
Delphi-Quellcode:
type
   TSelectionList = IDesignerSelections;
...
procedure TSecActionsEditor.lbActionsClick(Sender: TObject);
var
   ASelectionList : TSelectionList;
   i :integer;
begin
   if lbActions.SelCount = 1 then
   begin
      // Ein Elemet gewählt
      if lbActions.ItemIndex >=0 then
         TheDesigner.SelectComponent(FSecActionList.Actions[lbActions.ItemIndex]);
   end
   else
   begin
      // Mehrere Elemente gewählt
      ASelectionList := CreateSelectionList;
      for i := 0 to lbActions.SelCount-1 do
      begin
         ASelectionList.Add(FSecActionList.Actions[i]);
      end;
      TheDesigner.SetSelections(ASelectionList);
   end;
   UpdateSpeedBar;
end;
Vielleicht helfen diese Infos ja dem einen oder anderen, der Komponenten entwickelt.
Ibi fas ubi proxima merces
sudo /Developer/Library/uninstall-devtools --mode=all
  Mit Zitat antworten Zitat