Cannot access underlying event field
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_DoubleC开发者_如何学运维lick(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.
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.
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).
精彩评论