7

I am trying to cause TButton Click event from within TListBox doubleclick event by simply calling:

Button1.Click;

I am always able to do that under Delphi XE and version below it, but now it is raising an error in Delphi Prism. The error message is "Cannot access underlying event field." So, how would you cause an event from within an event of another control for instance TListBox?

for instance:

method UnitSelectDialog.UnitListBox_DoubleClick(sender: System.Object; e: System.EventArgs);
begin
   Okbtn.Click;
end;

The code above is same as if you clicked on the OK Tbutton on the form.

ThN
  • 3,235
  • 3
  • 57
  • 115

2 Answers2

5

I'm not familiar with Prism but this looks like the WinForms button to me. If so then you can call PerformClick.

OKbtn.PerformClick;

.net events are much more complex than VCL events. Most significantly they are multi-cast which means that multiple handlers can be attached. One consequence of this is that invoking events is much more complex.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 2
    Thanks it works. I know this is too simple of a question and I believe admins of StackOverflow have voiced that people are not asking more technical or important question anymore. When you are starting to learn and program in different or modified language or in this case .Net framework, you tend to ask a lot of little questions along the way. Thank You, StackOverFlow – ThN Aug 09 '11 at 16:18
  • 3
    I don't think this is too simple at all. No question is too simple. It's a perfect SO question. – David Heffernan Aug 09 '11 at 16:24
  • 2
    I agree with David. Perfect question for SO. – Rudy Velthuis Aug 09 '11 at 16:37
  • 1
    By the way, Prism looks like it would be pretty darned awesome. All that .net goodness with lovely Pascal syntax. Yum yum! – David Heffernan Aug 09 '11 at 22:50
  • Well, it IS pretty darned awesome ;-) And it even has a lot of language features that you miss in C#. – Sebastian P.R. Gingter Aug 10 '11 at 16:15
0

if you are defining your own class, a second option is to expose a public "raise" handler for the event, such as

event Click: ClickEventhandler; public raise;

this leads the compiler to make the proper method public so that other classes can call "Click()" to invoke the event. (of course any other non-private visibility works as well).

marc hoffman
  • 586
  • 1
  • 5
  • 14