Re: Delphi type events in C#

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi John,

have a look at these examples, they are pretty good
to understand:

http://msdn.microsoft.com/en-us/library/aa645739(VS.71).aspx

Thats a good one (just flying over it, looks good):

http://www.akadia.com/services/dotnet_delegates_and_events.html

regards

Kerem

--
--
----------------------- Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project: http://www.pro-it-education.de/software/deviceremover
Latest Open-Source Projects: http://entwicklung.junetz.de
----------------------- "This reply is provided as is, without warranty express or implied."

"JM" <me@xxxxxxxx> schrieb im Newsbeitrag news:eUkLIHGoJHA.2272@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

Being a Delphi programmer from way back (14 years) and new to C#, I was wondering if someone would be kind enough to explain how to create events in C# for non-visual controls/classes.

In Delphi, it's similar to..

procedure TMyNewEvent (Sender: TObject; MyStream: TStream; var MyFlag: boolean) Of Object;

In the containing class, it looks sort of like..

MyClass = class(TObject); // TPersistent or any TObject based class..
private
FOnMyEvent: TMyNewEvent;
protected
procedure DoMyEvent(Sender: TObject; AStream: TStream; var AFlag: boolean);
property OnMyNewEvent: TOnMyEvent Read FOnMyEvent Write DoMyEvent;
published
..
end;

And is then written as..

procedure MyClass.DoMyEvent(Sender: TObject; AStream: TStream; var AFlag: boolean);
begin
// do something here..
If Assigned(FOnMyEvent) Then
FOnMyEvent(Self, AStream, AFlag);
end;

In C#'lish, what would it look like?

I'm guessing callbacks/delegates or something similarly foreign to me.

I've only been looking at C# a few weeks and its similarities to Delphi are really quite remarkable in some areas..but, not this one.

Thanks in advance.

John McTaggart








.



Relevant Pages

  • Re: General Question On Handling of Function results.t
    ... might confuse another programmer working new on the project, ... > Best Regards ... >> use exception handling if you do not see anny other way, ... but a simple boolean is not enough. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: "with" Coders are Monsters
    ... class function TfrmSomeForm.ClassExecute: Boolean; ... Regards, ... that chaps my butt more than anything. ...
    (borland.public.delphi.non-technical)
  • Re: General Question On Handling of Function results.
    ... Best Regards ... i create a structure with the required info and ... > use exception handling if you do not see anny other way, ... but a simple boolean is not enough. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: SUMPRODUCT is making me mad!
    ... The double negation is not needed here since the addition operator coerces ... Boolean to numeric ... > Frank Kabel ...
    (microsoft.public.excel.worksheet.functions)