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
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?
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)
>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"
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
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)
--
>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.
>: 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;
>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.
>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.