Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Forms without Resources

576 views
Skip to first unread message

lawrence karthauser

unread,
Aug 13, 1999, 3:00:00 AM8/13/99
to
How do I create a form without having to have a resource file (DFM)

eg:

compile : g:\delphi3\bin\dcc32 test.pas

source:

program test;
uses Forms;
type
TFormTest = class(TForm)
end;
var
FormTest : TFormTest;
begin
Application.CreateForm(TFormTest, FormTEST);
Application.Run
end.

execute: c:\test\test

reason: to create component/utility/etc without any form files, just
the pas file

It says resource not found, but I am not using any. Can I creare a
resource on the fly to prevent this?

TIA

Lawrence

Liz Kimber

unread,
Aug 13, 1999, 3:00:00 AM8/13/99
to
You would have to create the form completely on the fly, such as

procedure makeform;
var form1 : Tform
label1 : Tlabel;

begin
form1:=Tform.create(nil);
form1.top:=1;
form1.left:=1;
form1.height:=200;
form1.width:=200;
form1.caption:='Created on the fly';
form1.showmodal;
form1.free;
end;


You have to set EVERY thing you want, any components you want to add
to the form you must set up also on the fly and also you must set
their parent to be the form etc.

Why dont you want to just have a form?

Mike Orriss (TeamB)

unread,
Aug 13, 1999, 3:00:00 AM8/13/99
to
In article <VA.00000019.0062a16e@lawrence>, Lawrence karthauser wrote:
> How do I create a form without having to have a resource file (DFM)

You can't - the DFM is the form.


> reason: to create component/utility/etc without any form files, just
> the pas file

Don't use any forms and place your code in the DPR file.


Mike Orriss (TeamB)
(Unless stated otherwise, my replies relate to Delphi 4.03)
(Unsolicited e-mail replies will most likely be ignored)


Ray Lischner

unread,
Aug 13, 1999, 3:00:00 AM8/13/99
to
On Fri, 13 Aug 1999 10:12:55 +0100, lawrence karthauser
<m...@pavilion.co.uk> wrote:

>How do I create a form without having to have a resource file (DFM)

Create an instance of TForm, and add to it any components you want.
--
Ray Lischner (http://www.tempest-sw.com/)
Author of "Hidden Paths of Delphi 3: Experts, Wizards, and the Open Tools API"

Thomas Pugh

unread,
Aug 13, 1999, 3:00:00 AM8/13/99
to
Sounds like you want a Unit, not a Form, since a Form always has a .DFM

Just select 'File | New | Unit' from Delphi


lawrence karthauser wrote in message ...


>How do I create a form without having to have a resource file (DFM)
>

>eg:
>
>compile : g:\delphi3\bin\dcc32 test.pas
>
>source:
>
>program test;
>uses Forms;
>type
> TFormTest = class(TForm)
> end;
>var
> FormTest : TFormTest;
>begin
> Application.CreateForm(TFormTest, FormTEST);
> Application.Run
>end.
>
>execute: c:\test\test
>

>reason: to create component/utility/etc without any form files, just
>the pas file
>

lawrence karthauser

unread,
Aug 14, 1999, 3:00:00 AM8/14/99
to
No, but I will create all the components on the form by hand, and so I
do not need, nor want the DFM. That I am clear on.

Lawrence


lawrence karthauser

unread,
Aug 14, 1999, 3:00:00 AM8/14/99
to
that is basically what I have done, but the code in this example is in
the main program, which of course would be the DPR normally. But why do
I need the DFM, since I am not going to put anything in it....

Lawrence


Ralph Friedman (TeamB)

unread,
Aug 15, 1999, 3:00:00 AM8/15/99
to
In article <VA.0000001b.085786bd@lawrence>, Lawrence karthauser stated:

> that is basically what I have done, but the code in this example is in
> the main program, which of course would be the DPR normally. But why do
> I need the DFM, since I am not going to put anything in it....
>
Lawrence,

if you truly want to do all of this at run time, you don't need the DFM.
The code would look something like:

This is Project1.DPR:

program Project1;

uses
Forms,
Unit2 in 'Unit2.pas';

{$R *.RES}

begin
Application.Initialize;
ShowForm;
Application.Run;
end.

and this is Unit2.Pas:

unit Unit2;

interface

uses Forms;

function ShowForm: TForm;

implementation

uses
StdCtrls;

function ShowForm: TForm;
begin
Application.CreateForm(TForm, Result);

with TEdit.Create(Result) do begin
Parent := Result;
Left := 12;
Top := 12;
Text := 'Edit';
end;
end;

end.

This is greatly over-simplified. There would be more issues (Events, etc)
to handle in a real-world case.

--
Regards
Ralph (TeamB)
--


Stefan Hoffmeister (TeamB)

unread,
Aug 15, 1999, 3:00:00 AM8/15/99
to
: delphi.at.te...@nospam.com (Ray Lischner) wrote:

>On Fri, 13 Aug 1999 10:12:55 +0100, lawrence karthauser
><m...@pavilion.co.uk> wrote:
>

>>How do I create a form without having to have a resource file (DFM)
>

>Create an instance of TForm,

... using the CreateNew constructor...

--
Stefan Hoffmeister (TeamB) http://www.econos.de/
Please do apply judgement when sending email.

Ray Lischner

unread,
Aug 15, 1999, 3:00:00 AM8/15/99
to
On Sun, 15 Aug 1999 11:26:47 GMT, Stefan.Ho...@Econos.de (Stefan
Hoffmeister (TeamB)) wrote:

>: delphi.at.te...@nospam.com (Ray Lischner) wrote:
>
>>On Fri, 13 Aug 1999 10:12:55 +0100, lawrence karthauser
>><m...@pavilion.co.uk> wrote:
>>
>>>How do I create a form without having to have a resource file (DFM)
>>
>>Create an instance of TForm,
>
>... using the CreateNew constructor...

Not necessary. TForm.Create does not try to load a DFM for class
TForm, only its descendants. Just create the TForm object normally,
and populate it at design time, e.g.,

Form := TForm.Create(Application);
Button := TButton.Create(Form);
Button.Parent := Form;
Button.Caption := 'Click Me';
Button.OnClick := DoSomething;
...
Form.Visible := True;

Stefan Hoffmeister (TeamB)

unread,
Aug 15, 1999, 3:00:00 AM8/15/99
to
: delphi.at.te...@nospam.com (Ray Lischner) wrote:

>Not necessary. TForm.Create does not try to load a DFM for class

Hm.

Last time - and IIRC - I tried that in C++Builder 4.0, I got problems and
was forced into using the equivalent of the CreateNew constructor.

Ray Lischner

unread,
Aug 15, 1999, 3:00:00 AM8/15/99
to
On Sun, 15 Aug 1999 19:09:41 GMT, Stefan.Ho...@Econos.de (Stefan
Hoffmeister (TeamB)) wrote:

>Last time - and IIRC - I tried that in C++Builder 4.0, I got problems and
>was forced into using the equivalent of the CreateNew constructor.

TForm* form = new TForm(Application);
TButton* button = new TButton(form);
button->Parent = form;
button->Caption = "Click me";
form->Visible = true;

The problem in C++ Builder would be if you tried to create a subclass
of TForm and avoid loading a DFM. If you just want a blank form that
you will populate at run time, creating a plain TForm works in Delphi
and in C++ Builder.

0 new messages