🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages Started by Jos� Wed, 14 Feb 2007 23:12
Dynamically creating control elements
#2566
Author: Jos�
Date: Wed, 14 Feb 2007 23:12
10 lines
1143 bytes
This is a stupid question of course, but I promise that I never did it
before.

How can I create and delete control elements (TEdit, TImage) on my
form while the program runs?

I thought "new TEdit" would do, but the compiler rejects this.

-- 
Jos�
Re: Dynamically creating control elements
#2567
Author: JD
Date: Wed, 14 Feb 2007 23:22
36 lines
1924 bytes
Jos� <jose@127.0.0.1> wrote:
>
> [...] I thought "new TEdit"

If you intend to use access the control after it's been
allocated, then you'll need to define a pointer for it
somewhere:

    private:
        TEdit *MyEdit;

then you need to allocate it and assign some properties:

    MyEdit = new TEdit( this );
    MyEdit->Parent = this;
    MyEdit->Left = 10;
    MyEdit->Top = 10;
    // set other properties as needed

Note that when it's allocated, an Owner is assigned and when
an object has an Owner, you need not worry about deleting it
because that's what the Owner is for. The Parent is where the 
control will live on-screen. For example, the 'this' pointer
referes to the class from which it's used and the TForm is
assumed here so the result will be a TEdit at (10,10).

For objects that do not have an Owner, you need to manually
destroy them before the application terminates. For example:

    delete MyEdit;

To be clear, even if the objects has an Owner, you can still
manually delete it.

~ JD
Re: Dynamically creating control elements
#2568
Author: Jos�
Date: Thu, 15 Feb 2007 08:07
9 lines
1137 bytes
On 14 Feb 2007 15:22:36 -0800, "JD" <nospam@nospam.com> wrote in
borland.public.cppbuilder.nativeapi:

>    MyEdit = new TEdit( this );
>    MyEdit->Parent = this;

Thanks, that worked. I didn't know how to use 'this'
-- 
Jos�
Re: Dynamically creating control elements
#2585
Author: Jos�
Date: Fri, 16 Feb 2007 22:57
13 lines
1263 bytes
On 14 Feb 2007 15:22:36 -0800, "JD" <nospam@nospam.com> wrote in
borland.public.cppbuilder.nativeapi:

>    MyEdit = new TEdit( this );
>    MyEdit->Parent = this;

Although it worked, and I also created forms with other owners, but I
have been unsuccesful in creating extra tabsheets, like this:

      TTabSheet *ts = new TTabSheet(PageControl2);
      ts->Parent=PageControl2;
-- 
Jos�
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads