473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 8868
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: achrist | last post by:
I'm aving some trouble getting callbacks from a Delphi DLL back to python working through ctypes. The call from python to the DLL works fine. In the Delphi(5) code: type TCallbackFunc =...
29
by: noid droid | last post by:
Hi. I've not used C# yet but just ran across a premonition from 2 years ago saying that C# would render C++ obsolete by this time. Has it? Have most corporate developers migrated to C#? Is...
6
by: Erva | last post by:
Hi, Is there someone who has moved from Delphi to VS.NET? I'am using Delphi currently but seriously considering to moving VS.NET. I would like to hear if someone has already done that, is it...
1
by: BlackTiger | last post by:
How to create analogue of Delphi's 'DataModule'? DataModule is non-visual form, which contains connections to DB, queries, tables, field definitions and relations between tables. All this...
10
by: Arda Han | last post by:
I am migrating my some applications from Delphi to C#. But... Yes But I don't know C# professionally. I am using DLL in delphi like this : ..... const RFID_103_485IO = 'Cihaz.dll'; ...
9
by: Chazza | last post by:
I would like to override a method from an inherited class, but the new method has a different signature to the inherited class. Example: class A { private void Init() { // code } } class B...
3
by: lukeharpin | last post by:
Currently I have been developing applications in Delphi 7. Recently I meet up with a friend of mine who previously developed in Delphi, from version 1 - 7. When Delphi 8 .net was release he found...
7
by: ray | last post by:
Ah well, it had to happen. Create a new form, minimum size 14cm by 14cm. Anywhere on the form, place 3 lines of any length called scrLineSecond, scrLineMinute and scrLineHour. Set the form's...
184
by: jim | last post by:
In a thread about wrapping .Net applications using Thinstall and Xenocode, it was pointed out that there may be better programming languages/IDEs to use for the purpose of creating standalone,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.