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 6928525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:11:57+00:00 2026-05-27T11:11:57+00:00

We have an application that have many components on the forms (panels, tabs, edits,

  • 0

We have an application that have many components on the forms (panels, tabs, edits, comboboxes, etc…). But depending on the user profile, most of them could be filled automatically and/or not be visible. So, users could do their work faster.

The question: Is there any easier way to create, position, change ownership etc, at runtime? I would like to create 2 .dfm files for a given unit and then have something to tell the application what .dfm to use. Like: “Hey! User is advanced, use the Unit1Advanced.dfm!” A working example would be nice. I would like to use that in Delphi 7 too, but it has to work at least in Delphi XE.

What I know that exist till now:

  1. ComponentsToCode function from GExperts can create code from a given component as gabr pointed in this answer.
  2. I could create 2 forms and create the desired one at runtime. But that means one additional .pas file to each additional .dfm file. This would be harder to maintain.
  3. This answer seems to give a hint. But I am not used to TReader and TWriter classes…
  • 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-27T11:11:58+00:00Added an answer on May 27, 2026 at 11:11 am

    Warning: This answer is for completeness sake to the question and is only for experimental purposes. It should never be used in real world scenarios.

    You want two separate form definition files for only one source code file.

    The key is to make use of the CreateNew constructor. To quote the documentation on it:

    Use CreateNew instead of Create to create a form without using the associated .DFM file to initialize it.

    1. First, write your advanced form:

      unit Advanced;
      
      interface
      
      uses
        Classes, Controls, Forms, StdCtrls;
      
      type
        TAdvancedForm = class(TForm)
          StandardGroupBox: TGroupBox;
            StandardButton: TButton;
          AdvancedGroupBox: TGroupBox;
            AdvancedButton: TButton;
          procedure StandardButtonClick(Sender: TObject);
          procedure AdvancedButtonClick(Sender: TObject);
        end;
      
      implementation
      
      {$R *.dfm}
      
      procedure TAdvancedForm.StandardButtonClick(Sender: TObject);
      begin
        Caption := Caption + ' Button1Click';
      end;
      
      procedure TAdvancedForm.AdvancedButtonClick(Sender: TObject);
      begin
        Caption := Caption + ' Button2Click';
      end;
      
      end.
      
    2. Build your app, and copy Advanced.dfm to Standard.dfm.

    3. Open Standard.dfm in a text editor and remove the advanced components (in this case the advanced group box containing a button), and rename the form and form type to (T)StandardForm:

      object StandardForm: TStandardForm
        ...
        object StandardGroupBox: TGroupBox
          ...
          object StandardButton: TButton
            ...
          end
        end
      end
      
    4. Add the resource for the standard form to Advanced.pas:

      {$R *.dfm}
      {$R Standard.dfm}
      
    5. And now with the following code, you can open both form definitions for the same source file:

      uses
        Advanced;
      
      procedure TForm1.OpenAdvancedFormClick(Sender: TObject);
      var
        Form: TAdvancedForm;
      begin
        Form := TAdvancedForm.Create(Application);
        Form.Show;
      end;
      
      procedure TForm1.OpenStandardFormClick(Sender: TObject);
      var
      {
        Form: TAdvancedForm; // This is tricky! The form we are about to create has
                             // no AdvancedGroupBox nor AdvancedButton, so make sure
                             // you are not calling it with code completion.
        Form: TStandardForm; // Compiler has no knowledge of TStandardForm!
      }
        Form: TForm;         // So declare your form as TForm!
      begin
        // But create it as TAdvancedForm, otherwise components will not be found!
        Form := TAdvancedForm.CreateNew(Application);
        ReadComponentRes('TStandardForm', Form);
        Form.Show;
      end;
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a System.Windows.Forms.Panel control in a windows application that has many labels and
I have an application that has many different types of objects that each persist
I have an application that writes many times to a formula/macro-laden workbook. It loops
I have an application that contains many controls on a panel, each with its
I have a multithreaded application that has many concurrent operations going on at once.
I have inherited a VB6/Access application that we have developed and sold for many
I have a legacy VB6 application that was built using MSDE. As many client's
In a C# Winforms (3.5) application I have added a class that contains many
I have an old function that is called many times in my application. I
I've creating a Java Swing application and I realized that I have many many

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.