Click here to Skip to main content
15,911,360 members
Home / Discussions / C#
   

C#

 
AnswerRe: I need a file viewr please Pin
Matthew Cuba10-Oct-07 15:39
Matthew Cuba10-Oct-07 15:39 
QuestionForm as Command Line Pin
SDEspiritu10-Oct-07 12:06
SDEspiritu10-Oct-07 12:06 
AnswerRe: Form as Command Line Pin
PIEBALDconsult10-Oct-07 13:13
mvePIEBALDconsult10-Oct-07 13:13 
GeneralRe: Form as Command Line Pin
PIEBALDconsult10-Oct-07 13:42
mvePIEBALDconsult10-Oct-07 13:42 
GeneralRe: Form as Command Line Pin
SDEspiritu11-Oct-07 4:48
SDEspiritu11-Oct-07 4:48 
QuestionIIS Configuration Pin
raygn210-Oct-07 11:40
raygn210-Oct-07 11:40 
AnswerRe: IIS Configuration Pin
Yitzchok Dev10-Oct-07 19:50
Yitzchok Dev10-Oct-07 19:50 
QuestionEvents should not return values?! Pin
Domenic Denicola10-Oct-07 11:14
Domenic Denicola10-Oct-07 11:14 
Hi there,

I have the following situation, which I've been handling through an event that returns a value. Apparently, this is bad coding practice!? If so, can someone tell me what I should be doing?

---

I have a class library. The user calls, say, GetMyPrivateInfo("password"). This private info may also be protected by a PIN. There are several other methods like GetMyPrivateInfo that may require a PIN for processing (but, they may not). It doesn't really make sense to ask for a PIN in the argument list of GetMyPrivateInfo and other such methods, especially since often a PIN might not be needed, if the user has decided not to protect certain data with a PIN (but instead just with a password).

Right now, I have a PinNeeded event handler, with return type int. If GetMyPrivateInfo determines that the info is in fact protected by a PIN, it will trigger PinNeeded and use the resulting integer PIN. If the PIN is not necessary, it won't trigger the event. And other methods in the class library can all use the PinNeeded event as well, when they need a PIN to get at certain data.

This works really well, because the user can log in to their account through my program, and the program doesn't know whether they have protected certain data with a PIN. So the program, which interfaces with the class library containing GetMyPrivateInfo, will subscribe to the library's PinNeeded event; the event handler will pop up a dialog box asking the user for his/her PIN, and if the user wants the program to remember the PIN for next time, then the event handler will in the future not pop up the dialog box but instead return the stored PIN. This is all in the program, not the class library. Now, the program calls GetMyPrivateInfo, because the user asked them to. The program still doesn't know if a PIN is needed, but the class library will find out, in the process of doing all the stuff in GetMyPrivateInfo. When GetMyPrivateInfo determines "I need a PIN to access this info," it calls the PinNeeded event handler, letting the program do its dialog-box/remembering thing, and uses the PIN to access the info and return it to the program.

Make sense? And it works really well.

---

But, I can see arguments that this actually isn't an "event," in some sense, but more of a request. But what's the correct coding paradigm for such a thing?

Thank you,


-Domenic Denicola- [CPUA 0x1337]

“I was born human. But this was an accident of fate—a condition merely of time and place. I believe it's something we have the power to change…”

AnswerRe: Events should not return values?! Pin
Christian Graus10-Oct-07 11:25
protectorChristian Graus10-Oct-07 11:25 
GeneralRe: Events should not return values?! Pin
Domenic Denicola10-Oct-07 11:31
Domenic Denicola10-Oct-07 11:31 
GeneralRe: Events should not return values?! Pin
Robert Rohde10-Oct-07 11:44
Robert Rohde10-Oct-07 11:44 
GeneralRe: Events should not return values?! Pin
Domenic Denicola10-Oct-07 11:57
Domenic Denicola10-Oct-07 11:57 
GeneralRe: Events should not return values?! Pin
lmoelleb10-Oct-07 20:53
lmoelleb10-Oct-07 20:53 
AnswerRe: Events should not return values?! Pin
Skippums10-Oct-07 11:39
Skippums10-Oct-07 11:39 
GeneralRe: Events should not return values?! Pin
Domenic Denicola10-Oct-07 11:42
Domenic Denicola10-Oct-07 11:42 
GeneralRe: Events should not return values?! Pin
Skippums11-Oct-07 4:57
Skippums11-Oct-07 4:57 
QuestionPublic and protected property Pin
Fernando A. Gomez F.10-Oct-07 11:07
Fernando A. Gomez F.10-Oct-07 11:07 
AnswerRe: Public and protected property Pin
Patrick Etc.10-Oct-07 11:08
Patrick Etc.10-Oct-07 11:08 
GeneralRe: Public and protected property Pin
Fernando A. Gomez F.10-Oct-07 11:13
Fernando A. Gomez F.10-Oct-07 11:13 
GeneralRe: Public and protected property Pin
Patrick Etc.10-Oct-07 11:44
Patrick Etc.10-Oct-07 11:44 
GeneralRe: Public and protected property Pin
Skippums10-Oct-07 11:23
Skippums10-Oct-07 11:23 
GeneralRe: Public and protected property Pin
Patrick Etc.10-Oct-07 11:44
Patrick Etc.10-Oct-07 11:44 
GeneralRe: Public and protected property Pin
Robert Rohde10-Oct-07 11:45
Robert Rohde10-Oct-07 11:45 
QuestionToolStripManager.LoadSettings exception Pin
Skippums10-Oct-07 10:42
Skippums10-Oct-07 10:42 
AnswerRe: ToolStripManager.LoadSettings exception Pin
Pete O'Hanlon10-Oct-07 10:50
mvePete O'Hanlon10-Oct-07 10:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.