Article View: borland.public.csharpbuilder.language.csharp
Article #247Passing by reference a bool argument to an event
From: Francois PIETTE [ICS - MidWare]
Date: Sun, 06 Aug 2006 13:40
Date: Sun, 06 Aug 2006 13:40
28 lines
2384 bytes
2384 bytes
I need to pass by reference a boolean value to an event handler. Since passing arguments to event handler involve using an intermediate class deriving from EventArgs, the reference argument loose his reference aspect because bool is a value-type. I need to pass a bool by reference to an event handler to implement default behaviour if no event handler is assigned and allow the event handler to select the action to be performed by setting the boolean value to true or false. Actually it is a used in a communication application when a timeout is detected an event is triggered, passing a boolean "CanClose" initialized to "true". If no handler is assigned to the event, CanClose is true. If an event handler is assigned, it can select to change CanClose to false. Then is the component code, CanClose is used to close the socket or not to close it. I designed a solution I don't like: I create a class with a boolean member and I used this class as argument type for my CanClose argument. Since class are always passed by reference, my event handler can change de boolean to whatever it likes, it is changed in the original class instance. So it does what I need but it is rather heavy code. Should be a better way to do that. -- francois.piette@overbyte.be The author for the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be
Technical Details
Message-ID:
<44d5f1b5@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,a225bfd0924d364f,start X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Francois PIETTE [ICS - MidWare]" <francois.piette@overbyte.be> Newsgroups: borland.public.csharpbuilder.language.csharp Subject: Passing by reference a bool argument to an event Date: Sun, 6 Aug 2006 15:40:33 +0200 Lines: 30 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 81.244.171.106 Message-ID: <44d5f1b5@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1154871733 81.244.171.106 (6 Aug 2006 06:42:13 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail