Article View: borland.public.cppbuilder.nativeapi
Article #9883Re: Creating child windows
From: JD
Date: Wed, 02 Jun 2004 07:27
Date: Wed, 02 Jun 2004 07:27
162 lines
6973 bytes
6973 bytes
"Don Peterson" <Ceedeep@aol.com> wrote:
>
Please wrap you lines when you post. You editor may visually
wrap them for you but you need to enter a hard return at the
end of each line.
So you know, your question is actually in the wrong news group.
This group is for questions about the win32 API's. A better
choice would have been the .vcl.components.using or the
.students group. You might want to take a look at the guide
lines for these groups:
http://info.borland.com/newsgroups/guide.html
> I'm new to Borland and to C++.
The most important thing that you need to learn is how to use
the help. Everything that you need to know (for now) is in
there. You should know how to search through help files to
find what you want but now you should depend on the help key
(F1) to get what you want.
If you select a component by clicking it and press F1, the
help will jump to the component. If you move the cursor into a
component's property and press F1, the help will jump to the
property. The same is also true for the event's of a component.
Note that sometimes, if the help is already open, you might
need to close it first and if you are presented with an choice
to select a CLX help topic v/s a VCL topic, always use the VCL
topic. CLX 'really close' to normal VCL but not exact.
The next thing is that if you don't know about classes, it
would be better if you did. It won't be as easy as it could be
to learn but the VCL is perfect for those just getting started.
As long as you're using the component's 'as is', you don't need
to know much.
> When Builder comes up, it invits me to construct a window
> and to generate code to go with it.
Take a look at the cpp file when you start a new project. The
IDE has automatically added a c'tor (constructor) to the
source file:
//-------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
// initialization code goes here
}
//-------------------------------------------------------------
Now, if you look at the available event's for the form, you'll
see OnCreate (and OnDestroy). These event's are delphi remnents
and *can* execute in an order that will cause all kinds of
problems so don't use them:
http://www.bcbdev.com/articles/suggest.htm#oncreate
Instead, put all of your initialization code in the c'tor and
your 'cleanup' code in the d'tor (destructor). The catch is
that the d'tor is not automatically added to the form by the
IDE so you have to do it.
//--- make the form's header file look like -------------------
public: // User declarations
__fastcall TForm1(TComponent* Owner);
__fastcall TForm1::~TForm1();
and then add this right under the c'tor:
//-------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
// cleanup code goes here
}
//-------------------------------------------------------------
> [...] Suppose in this window I want to query the user for
> his/her wishes with some radio buttons.
You need to know how a TRadioButton behaves with respect to the
VCL (I can't stress how important reading the help is). You'll
note that a TRadioButton presents a 'mutually exclusive' option
to the user. That means that if you put more than one on the
form, only one can be checked at a time.
The way around this is to put the TRadioButton(s) on (a) TPanel(s).
If the user has four settings and each of the 4 were mutually
exclusive, then you'd want 4 TPanel(s) and on the Panel's you'd
put as many TRadioButton(s) as were options for each setting.
That said, you most likely would rather be using a TRadioGroup
(also on the Standard tab).
Once you drop a component on the form and drag it to where you
want it, move over into the Object Inspector (left side of
screen). You'll see 2 tabs - Properties and Events.
While not 110% accurate, think of the component's Properties
as effecting the visual aspects of the control while the Event's
are there for you to tell the component what you want it to do
when certain things happen.
You can change a control's Property settings simply by moving
the cursor into the field and changing it. To add an event to
the control, select the specific event and double click it.
The IDE will generate the correct signature for the event and
add it to the form's source and header file. All you have to
do is fill-in the body of the event.
If you need to change the name you gave an event, do it in the
Object Inspector - not the source file. If you want to delete
an event, delete the body of the function (leaving the signature
that the IDE generated intact) and save the file. The IDE will
automatically remove empty events.
> [...] Depending on which button is hit, I invoke one of
> several other windows. But how do I do this?
There are several ways but I'll assume the method that you
want to know about is the most simple.
Click File | New | Form once for every window that you want
the application to have and then use the IDE to design it
(note that there is also a 'new form' icon).
Now go back to the main form (the first form is always the
main form) add, the header file's for the new form's by
clicking File | Include unit header.
Then double click your 'ok' button. The IDE will generate the
OnClick event signature (if it doesn't already exist) and take
you to it in your code.
To see what item in each TRadioGroup have been selected:
switch( RadioGroup1->ItemIndex )
{
case 0: // the first item is selected
break;
case 1: // the second item is selected
}
Once you've decided what TForm (window) you want to open, you
have to decide how you want to. You can:
Form2->Show();
which is the same as:
Form2->Visible = true;
Form2->SetFocus();
or
Form2->ShowModal();
~ JD
Technical Details
Message-ID:
<40bd8178$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!meganewsservers.com!feeder2.on.meganewsservers.com!216.196.98.140.MISMATCH!border1.nntp.dca.giganews.com!nntp.giganews.com!newsrout1.ntli.net!news-in.ntli.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40bbc5aa$1@newsgroups.borland.com> <40bbe2db@newsgroups.borland.com> <40bd2490@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,8a108b4b044d125f X-Google-Attributes: gid10cc67,public From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Re: Creating child windows Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 172.150.113.209 References: <40bbc5aa$1@newsgroups.borland.com> <40bbe2db@newsgroups.borland.com> <40bd2490@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <40bd8178$1@newsgroups.borland.com> Date: 2 Jun 2004 00:27:52 -0700 X-Trace: newsgroups.borland.com 1086161272 207.105.83.66 (2 Jun 2004 00:27:52 -0700) Lines: 163 Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!meganewsservers.com!feeder2.on.meganewsservers.com!216.196.98.140.MISMATCH!border1.nntp.dca.giganews.com!nntp.giganews.com!newsrout1.ntli.net!news-in.ntli.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail