Board index » delphi » !!!! Please help me with a simple question !!!!

!!!! Please help me with a simple question !!!!

Does anybody know how to make a button so when you click on it it will
open a new form?

Thankyou
-Phil

 

Re:!!!! Please help me with a simple question !!!!


Just put a TButton on your first Form and dobbelclick on it, (design time.)
Delphi will then jump into the code in the buttons OnClick event handler.
Here you can  put in this code:

procedure TMyForm.Button1Click(Sender: TObject);
begin
    MySecondForm.Show;   //or ShowModal, see Online Help
end;

Why don't you buy a Delphi book. They are all loaded with examples and you
can learn even more quickly!
--
Edgar Vorland

{Remove  '~' from mail adress. This is to avoid
spawn. Sorry! }
e~vorl...@readmatre.no

The Yakimaniacs <cmcc...@wolfenet.com> wrote in article
<346A4F26.6...@wolfenet.com>...

Quote
> Does anybody know how to make a button so when you click on it it will
> open a new form?

> Thankyou
> -Phil

Re:!!!! Please help me with a simple question !!!!


Quote
In article <346A4F26.6...@wolfenet.com>, cmcc...@wolfenet.com wrote:
>Does anybody know how to make a button so when you click on it it will
>open a new form?

pu the following code in the buttonclick event.

With Tform2.Create(Self) do
begin
    showmodal;
    free;
end;

The Graphical Gnome (r...@ktibv.nl)
Sr. Software Engineer IT Department
-----------------------------------------
The Unofficial Delphi Developers FAQ
http://www.gnomehome.demon.nl/uddf/index.htm

Re:!!!! Please help me with a simple question !!!!


Quote
The Yakimaniacs wrote in message <346A4F26.6...@wolfenet.com>...
>Does anybody know how to make a button so when you click on it it will
>open a new form?

>Thankyou
>-Phil

Phil:

All you need to do is the following:

Double-click on the button and place this code : form2. show;
Also in the uses section of unit1 add : , unit2
Let me know if this works.

Mark
-----------------
ma...@mtco.com

Re:!!!! Please help me with a simple question !!!!


Unless, of course, you mean that you want to show a NEW form (not one that
was created in your project). In that case, in the onclick event handler,
you need to do a

myform:=tform.create(self);

with myform being declared as a variable of type tform.

Quote
Mark Marzinzik wrote in message <346f4ac...@206.67.207.8>...

>The Yakimaniacs wrote in message <346A4F26.6...@wolfenet.com>...
>>Does anybody know how to make a button so when you click on it it will
>>open a new form?

>>Thankyou
>>-Phil

>Phil:

>All you need to do is the following:

>Double-click on the button and place this code : form2. show;
>Also in the uses section of unit1 add : , unit2
>Let me know if this works.

>Mark
>-----------------
>ma...@mtco.com

Re:!!!! Please help me with a simple question !!!!


I guess that depends of what you mean by "new form". If you want a
pushbutton to open another form (already created), then the following code
attached to the pushbuttons on onclick method would do the trick:

formname.show ;

--
Greg R. Johnson
CompuCom
gjohn...@mail.icongrp.com
http://cgi.icongrp.com/~gjohnson/

Quote
The Yakimaniacs wrote in message <346A4F26.6...@wolfenet.com>...
>Does anybody know how to make a button so when you click on it it will
>open a new form?

>Thankyou
>-Phil

Re:!!!! Please help me with a simple question !!!!


Greetings,

    The code "with TForm.Create (Self) do" will do fine,  as long as the
form created this way doesn't need to be accessed by *any* other form.
The reason is that it will cause an access violation if it does. The
create function returns a pointer initialized to the address of the form
being created. When a form is created this way, the return value of the
create function is ignored. If you try and access objects on the first
form, to change the caption of a label on it for example, then you will
generate an access violation because the (changer) form doesn't know
where to find the form created that way, as there is no pointer to it.
    If I am wrong and have missed something, would someone please tell
me so I don't pollute?

Regards All,

--
Edward Garson
Flairbase Inc.
edward@NO_SPAMshuya.ml.org

Other Threads