2

This never happened to me before.

I do have System.Windows.Forms namespace under uses clause and I am able to use DialogResult's properties. Look at the code below. It's where the problem is in my program.

if (thewinform.ShowDialog=DialogResult.OK) then

I did debug it and dialog winform opens. Once I click the OK button and returns to check on the DialogResult, it skips the if block of code. At which point, I noticed that DialogResult is actually NIL

I never encountered anything like this before.

Any ideas? Thanks,

Ken White
  • 123,280
  • 14
  • 225
  • 444
ThN
  • 3,235
  • 3
  • 57
  • 115
  • Is this VB or C#, Or delphi, as your tags seem to suggest? – Dan Puzey Oct 23 '12 at 14:42
  • @DanPuzey _"Delphi Prism is a rapid application development tool for the Microsoft .NET Framework and Mono"_. Also the `=` and `nil` should've given Delphi away. – CodeCaster Oct 23 '12 at 14:42
  • I've been fortunate enough to avoid Delphi my entire career (so far, touch wood, etc), so the `nil` was a curiosity rather than a signpost :) A single `=` could have been VB, or could have been bad C#. – Dan Puzey Oct 23 '12 at 14:44
  • @DanPuzey: yeah, that's why I got downvoted. People expect everybody to know and think Delphi, even though the language is near dead. – Victor Zakharov Oct 23 '12 at 14:46
  • @Neolisk, I know what you mean. I've been downvoted for asking stupid question too before on Stackoverflow. – ThN Oct 23 '12 at 14:47
  • @Neolisk: you were probably just downvoted because it's not a useful answer to the question. I could have posted the same thing but I recognised that I'd be assuming a language that the question hadn't specified - that's what the comments here are for ;-) – Dan Puzey Oct 23 '12 at 14:51
  • @DanPuzey, I thought that's why you have to attach tags with your question. Clearly, it does say "delphi-prism." Anyways, if you could give me any help. I would appreciate it. Thanks, – ThN Oct 23 '12 at 14:54
  • @DanPuzey: How about posting a useful answer first, and then downvoting? 2 points don't make a deal, considering they are revertible - just annoying. – Victor Zakharov Oct 23 '12 at 14:55
  • @Neolisk: for clarity, I haven't downvoted you, I'm just trying to explain why you might have been. The fact that someone else doesn't have a good answer doesn't stop yours from being non-useful. Non-useful answers get downvoted: it's what makes this site work! Since you've recognised that your answer is wrong, you could also delete it - which will prevent any further downvotes and further improve the content of the site. Also, point of note: StackOverflow isn't about scoring points. – Dan Puzey Oct 23 '12 at 14:58
  • @DanPuzey: this is a topic for discussion - why the approach you described does not always work. Unfortunately, stackoverflow is not a place for such. I will delete my answer and get downvotes back. – Victor Zakharov Oct 23 '12 at 15:01
  • @DanPuzey, " this site isn't about scoring points " Not true I say. Having a huge points next to your name and picture says a lot about you, even though the points don't really mean anything. – ThN Oct 23 '12 at 15:01

1 Answers1

3

I found the answer to my question.

When you want to use a winform purely as a dialog box, then you CANNOT have FormClosing event.

For my thewinform, I accidently created its FormClosing event and forgot about it.

method thewinform.thewinform_FormClosing(sender: System.Object; e: System.Windows.Forms.FormClosingEventArgs);
begin
    e.Cancel := true;
    hide;  
end;

Once I removed this winform event, ShowDialog and DialogResult is behaving as expected.

This is very similar to another stackoverflow question Why does ShowDialog always return DialogResult.Cancel?

Community
  • 1
  • 1
ThN
  • 3,235
  • 3
  • 57
  • 115