Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7538429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:07:09+00:00 2026-05-30T07:07:09+00:00

I’m trying to run a GUI unit test with DUnit to an application whose

  • 0

I’m trying to run a GUI unit test with DUnit to an application whose mainform creates dynamically frames to itself. I’ve been able to create the application-to-test’s mainform as a form in the test case and access its menu items etc.

The problem comes when the application tries to create a frame dynamically. The frame’s resource reading comes to a point where it needs the window handle (in my case, setting the caption of a tab sheet). Here it goes from TWinControl.GetHandle to TWinControl.CreateWnd and to TCustomFrame.CreateParams.

In this CreateParams, the code says:

  if Parent = nil then
    Params.WndParent := Application.Handle;

This is where the difference occurs. When I run the actual application (not in the test), the Application.Handle here returns a non-zero number and the flow continues ok. But in the DUnit test application, the Application.Handle here returns 0. This causes the code in the TWinControl.CreateWnd to raise an exception telling that the frame does not have a parent:

  with Params do
  begin
    if (WndParent = 0) and (Style and WS_CHILD <> 0) then
      if (Owner <> nil) and (csReading in Owner.ComponentState) and
        (Owner is TWinControl) then
        WndParent := TWinControl(Owner).Handle
      else
        raise EInvalidOperation.CreateFmt(SParentRequired, [Name]);

I’d like to try to get around this problem (and in general, all test problems) without modifying the “production” code just because of the tests. Can you provide any clues on whether I could somehow force the “Application” to something else, or in some other way work around this?

Looking at the code, a possible other workaround scenario might be to try to get the owner (which is my “MainForm” of the application-to-test, i.e. whose handle I’d want to get) to be in csReading state while doing this frame creation in the test, but at least initially it doesn’t seem so straightforward to get this to happen either.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:07:11+00:00Added an answer on May 30, 2026 at 7:07 am

    Thanks for all the comments and replies!
    I believe to have solved the issues, at least ones found out so far.
    I’ll summarize my findings and final situation below (in case someone else would find any of this useful).

    I have a test decorator class inheriting from TTestSetup, which holds a reference to a dummy (main) form that it creates when necessary.

    I also found a way to switch the Application.MainForm on runtime using approach like this: http://www.swissdelphicenter.ch/torry/showcode.php?id=665

    In the test decorator SetUp method I create first the dummy form and then set it as the main form of the Application (this setting might not be necessary here).

    Then I have a test case class (inheriting from TGUITestCase), whose SetUp and TearDown are run for each test. In this SetUp I create the mainform that I’m testing and then set it as the Application’s main form. Then after the test in the test case’s TearDown, I set the dummy form again to be the main form of the Application, and only after this call Close and Free to the mainform that I’m testing. Otherwise freeing a form that is currently the Application.MainForm would cause the entire DUnit application to terminate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.