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

  • Home
  • SEARCH
  • 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 506879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:44:47+00:00 2026-05-13T06:44:47+00:00

Is it possible to edit a DFM (Delphi’s form script format) in such a

  • 0

Is it possible to edit a DFM (Delphi’s form script format) in such a way that a form closes itself when shown?

I don’t code in Delphi, so I’m not familiar with how these forms work, but it seems I could put code (but not standard Delphi code as it seems) in the OnShow or OnCreate events of the form. However, after trying several statements like Close, Exit, FormNameExit, Destroy, etc. won’t work (a log will be created, stating the error that the value of the OnShow property was invalid, etc.)

The normal way of closing the form is through a button, but the button doesn’t have a OnClick event, just a property, “ModalResult = 1“.

Is there a way to make the window close upon opening, some standard function I could put on the OnCreate or OnShow events of the form? Or maybe, creating a checkbox on the form itself, that gives ModalResult = 1? (don’t know if this works)

Thanks for any suggestion!
=)

(Note: maybe it’s obvious, but I don’t have the source.)

  • 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-13T06:44:48+00:00Added an answer on May 13, 2026 at 6:44 am

    EDIT: Seeing some of your comments added while I typed my text-wall clarifies things a bit.

    I’m guessing that you you’re using a resource editor to edit the DFM and modify the behaviour of the app without actually touching the source code?

    In this case, the best you could try is to set the Visible property to False. However, this will have no benefit if the developer ‘actively displays the form in code’. (He could have done this by calling Show, ShowModal or even by explicitly setting the Visible property.)

    Unfortunately, if this is the case, then there’s nothing you can do without modifying the actual source code. This is because the DFM is processed when the form is loaded; i.e. before the developer’s code that shows the form. Even looking for a place to set ModalResult is useless, because the current ModalResult is cleared when ShowModal is called.

    I don’t think I understand exactly what you’re trying to do, because it doesn’t make sense.
    It seems to me that you want the form to be automatically closed as soon as it is shown; and that doesn’t make sense. :S
    So, if I have understood you correctly, please explain why you would want to do this; there may be a better solution for your actual problem.

    However, some general concepts…

    • If you want a form to close, you should link it to some action that closes the form. Either put a button on the form, or a menu item.
    • Standard forms have a standard Windows mechanism to close them by default. (I.e. the X on the top-right.)
    • There are two ways of showing forms, and the way in which it is shown does have an effect on how it will be closed. It can be shown modally (which means it is the only form of the application which will interact with the user), or it can be shown normally (which allows the user to switch between other forms of the application).
      • The point of showing a form modally is that it blocks the flow of your code until the user has finished doing something that was required; it often involves the user providing some form of answer or confirmation.
      • When shown modally, the form should rather be closed with a ModalResult.
      • When shown normally, the ModalResult has no effect.
    • Whenever a form is ‘closed’, there are a few ways in which this can be done.
      • The form can simply be hidden; it’s still there, but invisible. Next time you want to show the form, you just make it visible again.
      • The form can be destroyed; meaning that it no longer exists in memory. If this is done, then next time you want to use the form, you have to recreate it.
      • The attempt to close the form can be actively prevented (Not usually advisable; but may be necessary in specific cases – if for example some information on the form is incorrect).
      • The form may be simply minimised (this is often done with MDI child forms).
    • NOTE: There are also a number of attributes on forms (FormStyle being the most important) that have an effect on how it behaves, displays, and can be closed. (E.g. MDI Child forms will by default either minimise, or do nothing when closed.)
    • NB:If the main form of an application is properly closed, then the application will shut down.

    Now, some of the technicalities…

    • As mentioned earlier a form can be displayed either modally, or normally; using either MyForm.Show; or ModalResult := MyForm.ShowModal;
      • NOTE: If the form was shown modally, you then need to check the ModalResult to find out the user’s answer and act accordingly.
    • If you displayed the form modally, you should set the ModalResult and the form will close itself. An easy way to do this is to assign a ModalResult to the buttons on the form; then the button will automatically set the form’s ModalResult when clicked.
    • If you displayed the form normally, then all you need to do is call MyForm.Close at the appropriate point in time. NB: Note their are other ways to ‘close’ a form, but it is better to use this method because it allows you to handle the OnCloseQuery event which is a mechanism to confirm whether the form is allowed to close.
    • NOTE: While closing the form, there are two events that Delphi can call which you can handle in order to modify how the closing of the form behaves:
      • OnCloseQuery is called to confirm whether the form is allowed to close.
      • OnClose is called to find out how the form should close (as explained previously).

    Coming back to your question (which sounds like you want the form closed automatically). Rather than closing the form automatically; just don’t bother showing it. This is very easy to do. All forms have a Visible property; if set to True, Delphi will automatically show the form normally when it is created. So all you need to do is ensure the property is False.

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

Sidebar

Ask A Question

Stats

  • Questions 378k
  • Answers 378k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I guess you don't mean to find the best look… May 14, 2026 at 9:13 pm
  • Editorial Team
    Editorial Team added an answer There is an easy way to get rid of the… May 14, 2026 at 9:13 pm
  • Editorial Team
    Editorial Team added an answer The properties are declared assign instead of retain for a… May 14, 2026 at 9:13 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.