Question

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,

Était-ce utile?

La solution

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?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top