2

I have been trying to do a GUI test with DUnit which includes interacting with modal windows via a message loop timer system by @tomazy (see my earlier question for more details: (How) Can I use FutureWindows with standard file open dialogs? ).

My solution in the other question works fine when I run the tests manually, but when I run this within a continuous build system in TeamCity, it hangs when the dialog's OK message should be handled. The service that runs the tests has the permission "interact with desktop" set, and I have verified that the hanging happens ONLY if the OK is pressed (i.e. the CDN_FILEOK notification happens). I can close the dialog using WM_CLOSE, but this naturally does not cause the dialog to return an OK modal result, and thus is not usable.

If I can't get this to work, I'll probably have to modify the production code (target of test) to publish an event to give the filename and have the test hook into it and give it without a dialog, but I'd like to know what is causing this problem and preferably of course solve it without modifying the production code.

Community
  • 1
  • 1
DelphiUser
  • 419
  • 4
  • 12
  • Are you running this in Vista and up? If so it's quite possible that you are falling foul of the session 0 isolation problem. – David Heffernan Mar 01 '12 at 09:18
  • Yes, this is Windows 7. I'm puzzled that some (most) messages seem to work without problems but only the crucial one (OK) hangs. I've verified this by trying to close the dialog with sending return key and sending (and posting, tested with both) mouse button down+up messages to the "open" button and just sending WM_CLOSE, and it hangs in the "OK case", i.e. with return key or on the mouse up of the up-down pair (click). – DelphiUser Mar 01 '12 at 09:39
  • Is this a special Windows-specific standard dialog (a CDN_FILEOK notification is new for me)? Or can you reproduce the problem with a self made dialog too? – mjn Mar 01 '12 at 09:43
  • It's a standard file-open dialog. The notification info I picked up from here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646857%28v=vs.85%29.aspx and also in Vcl.Dialogs.TOpenDialog.WndProc method where it has a case for WM_NOTIFY and under it a case for CDN_FILEOK (in LOFNotify.hdr.code, which is created from LParam). I haven't tried with a self-made dialog, can try that... – DelphiUser Mar 01 '12 at 09:49
  • Using a dummy self-created form like below it worked. This form of course has no WndProc of its own. `MyForm := TForm.Create(nil); MyBtn := TButton.Create(MyForm); MyBtn.ModalResult := mrOk; MyBtn.Parent := MyForm; TFutureWindows.Expect(TForm.ClassName) .ExecProc( procedure (const AWindow: IWindow) var TheForm: TForm; begin TheForm := AWindow.AsControl as TForm; (TheForm.Controls[0] as TButton).Click; end ); Result := MyForm.ShowModal = mrOk; MyForm.Free;` – DelphiUser Mar 01 '12 at 10:10
  • Hmm, couldn't seem to get multi-line code very nicely on comment :( – DelphiUser Mar 01 '12 at 10:15
  • "This form of course has no WndProc of its own." Sure it does. All windows have a `WndProc`. In this case it is implemented by the VCL messaging framework. – David Heffernan Mar 01 '12 at 10:25
  • Well, I meant no overriden special implementation of WndProc of its own. – DelphiUser Mar 01 '12 at 11:04

0 Answers0