TAction/es

From Lazarus wiki
Revision as of 09:07, 29 March 2017 by Jma sp (talk | contribs) ()
Jump to navigationJump to search

Un objeto TAction es un contenedor para tópicos específicos de relación de acciones tales como eventos, descripción, tópicos de ayuda, icono, shortcut. Cuando se utiliza TActions en la propiedad Actions de los pulsadores, menús, diálogos, controles, es posible centralizar los efectos de los clicks del ratón, elecciones de menú, selecciones de diálogo, shortcuts, etc en un único manejador de eventos.

Ejemplo e

Necesitamos tener un TAction que maneje la apertura de algún otro formulario. Nos aseguramos que tenemos un TActionList en el formulario principal. Doubleclick the TActionList to get the ActionList Editor. Create a new action by hitting the plus-sign. In the Object Inspector, set the name to actSomeAction, set a desired shortcut, a caption to be uses in menu's, an imageindex if a TImageList is connected to the parent ActionList, Hint is hints are to be displayed, helpkeyword and other properties where relevant.

The most important is the OnExecute-event that will be executed if the action is triggered somehow (menu, shortcut, button).

procedure TMyForm.actSomeActionExecute(Sender: TObject);
var
  f: TSomeForm;
  rv: integer;
begin
  f := TSomeForm.Create( nil );
  f.Caption := 'SomeForm';
  rv := f.ShowModal();
  if rv=mrOk then
    DoSomethingMeaningful();  
  f.Free();
end;

If you use the newly created action in a TMenuItem of a TMainMenu or TPopupMenu you are ready to go.

See also