Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p><strong>Warning:</strong> This answer is for completeness sake to the question and is only for experimental purposes. It should never be used in real world scenarios.</p> </blockquote> <p>You want two separate form definition files for only one source code file.</p> <p>The key is to make use of the <a href="http://docwiki.embarcadero.com/VCL/en/Forms.TCustomForm.CreateNew" rel="nofollow"><code>CreateNew</code></a> constructor. To quote the documentation on it:</p> <blockquote> <p>Use CreateNew instead of Create to create a form without using the associated .DFM file to initialize it.</p> </blockquote> <ol> <li><p>First, write your advanced form:</p> <pre><code>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. </code></pre></li> <li><p>Build your app, and copy <code>Advanced.dfm</code> to <code>Standard.dfm</code>.</p></li> <li><p>Open <code>Standard.dfm</code> 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 <code>(T)StandardForm</code>:</p> <pre><code>object StandardForm: TStandardForm ... object StandardGroupBox: TGroupBox ... object StandardButton: TButton ... end end end </code></pre></li> <li><p>Add the resource for the standard form to <code>Advanced.pas</code>:</p> <pre><code>{$R *.dfm} {$R Standard.dfm} </code></pre></li> <li><p>And now with the following code, you can open both form definitions for the same source file:</p> <pre><code>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; </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload