471,318 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

What is C#'s analogue of Delphi's TAction ?

What is C#'s analogue of Delphi's TAction ?

If there is no one, how to implement the same functionality >

Oleg Subachev
Jan 13 '06 #1
7 8693
Oleg Subachev wrote:
What is C#'s analogue of Delphi's TAction ?

If there is no one, how to implement the same functionality


It would help if you could say what TAction does - otherwise you've
limited yourself to those who know both Delphi and C#.

Joanna? :)

Jon

Jan 13 '06 #2
> It would help if you could say what TAction does

TAction is a class that mainly has two events:
OnExecute - where some real job may be done
and
OnUpdate - where the instance may be enabled/disabled.

Then the TAction instance may be assigned to the special
property of different controls, such as menu item, button,
speed button etc. So that all these controls will perform
the same job on clicking. Also these controls will be
simultaneously enabled/disabled and may share common
Caption, Hint and other properties.

Oleg Subachev
Jan 13 '06 #3
Oleg Subachev wrote:
It would help if you could say what TAction does


TAction is a class that mainly has two events:
OnExecute - where some real job may be done
and
OnUpdate - where the instance may be enabled/disabled.

Then the TAction instance may be assigned to the special
property of different controls, such as menu item, button,
speed button etc. So that all these controls will perform
the same job on clicking. Also these controls will be
simultaneously enabled/disabled and may share common
Caption, Hint and other properties.


I don't believe there's anything similar in the .NET framework.
However, you could create a class which aggregated a list of controls,
and allowed you to manipulate them (enable/disable etc) as a group
(just by looping through the list when you asked the instance to do
something).

Jon

Jan 13 '06 #4
"Jon Skeet [C# MVP]" <sk***@pobox.com> a écrit dans le message de news:
11**********************@o13g2000cwo.googlegroups. com...

| It would help if you could say what TAction does - otherwise you've
| limited yourself to those who know both Delphi and C#.
|
| Joanna? :)

You rang ?

TAction is a non-visual component that can be added to a TActionList using a
component editor. Basically, controls like buttons and menu items have an
Action property and a TAction provides a RAD way of specifying what happens
when button or menu item is clicked. It provides an OnHint event where the
Hint value can be supplied as an when required and an OnExecute and OnUpdate
where you can specify what happens when the control is clicked and what how
to alter the client controls' state when things like Enabled or Checked
change. A TAction can be attached to several controls so that there is a
single place where code for a single "Action" like Copy, Cut or Paste, etc
can react to a button, popup menu and main menu for the same action.

To set up a TAction, place a TActionList on a form and then use the
component editor to add TActions to it. Add code to the event handlers and
then hook up whatever controls need to call that Action by setting the
Action property of those controls to one of the Actions in the list.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 13 '06 #5
"Jon Skeet [C# MVP]" <sk***@pobox.com> a écrit dans le message de news:
11**********************@g14g2000cwa.googlegroups. com...

| I don't believe there's anything similar in the .NET framework.
| However, you could create a class which aggregated a list of controls,
| and allowed you to manipulate them (enable/disable etc) as a group
| (just by looping through the list when you asked the instance to do
| something).

Oleg, take a look at creating a Component derivative that implements
IExtenderProvider. Make sure that it is capable of capturing the Click event
of Control. This will set you in a similar direction; I suggest that you
look at the source for TControl, TActionLink and TActionList to see how
Delphi works, and then simplify what you see.

Here's a starter :

[ProvideProperty("InvokeAction", typeof(Control))]
public class ActionProvider : Component, IExtenderProvider
{
private class Properties
{
private bool invokeAction = false;

public bool InvokeAction
{
get { return invokeAction; }
set { invokeAction = value; }
}
}

private Hashtable properties = new Hashtable();

private EventHandler execute;

public event EventHandler Execute
{
add { execute += value; }
remove { execute -= value; }
}

public ActionProvider(IContainer parent)
{
parent.Add(this);
}

bool IExtenderProvider.CanExtend(object obj)
{
return obj is Control;
}

private Properties EnsurePropertiesExists(object key)
{
Properties p = (Properties) properties[key];

if (p == null)
{
p = new Properties();

properties[key] = p;
}

return p;
}

[Category("Behaviour")]
[Description("Calls centralised event handler for Click event of linked
controls")]
[DefaultValue(false)]
public bool GetInvokeAction(Control c)
{
return EnsurePropertiesExists(c).InvokeAction;
}

public void SetInvokeAction(Control c, bool value)
{
EnsurePropertiesExists(c).InvokeAction = value;

if (value)
c.Click += HandleClick;
else
c.Click -= HandleClick;
}

private void HandleClick(object sender, EventArgs args)
{
if (!DesignMode)
{
Control control = (Control) sender;
if (control != null && execute != null)
{
execute(this, EventArgs.Empty);
}
}
}
}
Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 13 '06 #6
>TAction is a non-visual component that can be added to a TActionList using a
component editor. Basically, controls like buttons and menu items have an
Action property and a TAction provides a RAD way of specifying what happens
when button or menu item is clicked.


Very convenient way of doing things, which is - unfortunately - sorely
lacking from the .NET framework. Makes you wonder why.....

There are a number of free and commercial "replacements" for this
annoyance.

There are a number of pretty straightforward "Delphi-to-C#"
translations up on CodeProject - see these for instance:

Simplifying GUI development with Actions
http://www.codeproject.com/csharp/ac...stprovider.asp

ActionLists for Windows.Forms
http://www.codeproject.com/cs/miscctrl/actionlist.asp

Or there's the commercial package by some former Delphites called
"CommandMaster" which can be found here:
http://www.componentscience.net/Prod...3/Default.aspx

No personal experience with any of those, though.

Marc
Jan 14 '06 #7
Sergio
2
nxSharp Actions for .NET - fully functional analog of Delphi ActionList with additional features.

http://nxsharp.com/
Mar 22 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by achrist | last post: by
6 posts views Thread by Erva | last post: by
10 posts views Thread by Arda Han | last post: by
3 posts views Thread by lukeharpin | last post: by
7 posts views Thread by ray | last post: by
184 posts views Thread by jim | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.