Google Groups Home
Help | Sign in
How to assign values to several dynamiclay created TEdit's
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  15 messages - Expand all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Oren Halvani  
View profile
 More options Jul 19 2004, 9:24 am
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Oren Halvani" <NoS...@fdtd.com>
Date: Mon, 19 Jul 2004 15:24:27 +0200
Local: Mon, Jul 19 2004 9:24 am
Subject: How to assign values to several dynamiclay created TEdit's
hi dear builders,

a while ago Remy posted me a sample how to create 20 dynamic TEdit's..

my problem is that i've got a ComboBox, that gives the user the option
to "feed" the dynamicaly created TEdit's with several values...BUT how
do i access the TEdit's ?? Their names are created in the constructor..
and i need to access them from a TButton->OnClick(...) and here they
are unknown, so how is it possible?

can someone please help me on that..?

Oren

/***************************************************************/
std::vector<TEdit*> Edits; // global..

__fastcall Form1::Form1(TComponent* Owner) : TForm(Owner)
{
   const int b = 20;  const int width = 110;   const int height = 21;

   Edits.clear();
   int anzahl = 20;

   for(int x = 0; x < anzahl; ++x)
   {
     TEdit *LeftEdit = new TEdit(this);
     LeftEdit->Parent = this;
     LeftEdit->Name = "txtLeft" + IntToStr(x);  // HERE i'm creating the names
(left Edit's)
     //...
     LeftEdit->SetBounds(4, b + (height*x) + 2, width, height);

     TEdit *RightEdit = new TEdit(this);
     RightEdit->Parent = this;
     RightEdit->Name = "txtRight" + IntToStr(x);  // HERE i'm creating the names
(right Edit's)
     //...
     RightEdit->SetBounds(6 + width, b + (height*x) + 2, width, height);
     RightEdit->Tag = reinterpret_cast<int>(LeftEdit);
     Edits.push_back(RightEdit);
   }

}

// here i feed the TEdit's...

void __fastcall Form1::cmdInsert_SampleClick(TObject *Sender)
{
   switch(Box_Sample->ItemIndex)  //ComboBox
   {
     case 0:
             txtLeft0->Text = "Ä"; txtRight0->Text = "&Auml;";
             txtLeft1->Text = "Ö"; txtRight1->Text = "&Ouml;";
             txtLeft2->Text = "Ü"; txtRight2->Text = "&Uuml;";
             txtLeft3->Text = "ä"; txtRight3->Text = "&auml;";
             txtLeft4->Text = "ö"; txtRight4->Text = "&ouml;";
             txtLeft5->Text = "ü"; txtRight5->Text = "&uuml;";
             txtLeft6->Text = "ß"; txtRight6->Text = "&szlig;";
             break;

             //...
   }


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hans Galema  
View profile
 More options Jul 19 2004, 10:06 am
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: Hans Galema <dontuset...@dontusethis.nl>
Date: Mon, 19 Jul 2004 16:06:04 +0200
Local: Mon, Jul 19 2004 10:06 am
Subject: Re: How to assign values to several dynamiclay created TEdit's

Oren Halvani wrote:
> my problem is that i've got a ComboBox, that gives the user the option
> to "feed" the dynamicaly created TEdit's with several values...BUT how
> do i access the TEdit's ?? Their names are created in the constructor..
> and i need to access them from a TButton->OnClick(...) and here they
> are unknown, so how is it possible?

You pushed all your TEdit's in -which you forgot to mention-:

     std::Vector<TEdit*> Edits;

So simply loop through Edits looking for the wanted Name.

Hans.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Remy Lebeau (TeamB)  
View profile
 More options Jul 19 2004, 1:05 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Remy Lebeau \(TeamB\)" <gambit47.no.s...@no.spam.yahoo.com>
Date: Mon, 19 Jul 2004 10:05:44 -0700
Local: Mon, Jul 19 2004 1:05 pm
Subject: Re: How to assign values to several dynamiclay created TEdit's

"Oren Halvani" <NoS...@fdtd.com> wrote in message

news:40fbcb5d@newsgroups.borland.com...

> BUT how do i access the TEdit's ??

You need to pay more attention to the code samples I give you.  I already
showed you how to access them.

Gambit


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oren Halvani  
View profile
 More options Jul 19 2004, 1:31 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Oren Halvani" <NoS...@fdtd.com>
Date: Mon, 19 Jul 2004 19:31:48 +0200
Local: Mon, Jul 19 2004 1:31 pm
Subject: Re: How to assign values to several dynamiclay created TEdit's

"Remy Lebeau (TeamB)" <gambit47.no.s...@no.spam.yahoo.com>
 schrieb im Newsbeitrag news:40fbff33$1@newsgroups.borland.com...

> "Oren Halvani" <NoS...@fdtd.com> wrote in message
> news:40fbcb5d@newsgroups.borland.com...

> > BUT how do i access the TEdit's ??

> You need to pay more attention to the code samples I give you.  I already
> showed you how to access them.

> Gambit

OK, i could do it like that:

void ins(TEdit *one)
{
   one->Text = "ä";

}

// But..

void __fastcall TfrmMulti_StringReplace::cmdInsert_SampleClick(TObject *Sender)
{
    std::for_each(Edits.begin(), Edits.end(), ins); // I DO NOT NEED ALL
EDIT'S..only 7

     //....

}

Oren

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Howard  
View profile
 More options Jul 19 2004, 2:10 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: Tim Howard <tim_N0SPAM_@netsimplex_NOSPAM_.com>
Date: Mon, 19 Jul 2004 13:10:25 -0500
Local: Mon, Jul 19 2004 2:10 pm
Subject: Re: How to assign values to several dynamiclay created TEdit's
OK,

First off, you can just do a vector.at( someint ) and get just the one
you need.

Also, you might want to consider a map if you need to access certain
"random" TEdits. Like mapping an identifier that you make up like some
integer to keep track of them.

map< int, TEdit* > someMap;

Then when you put them in your map simliar to this

someMap[ 1 ] = thisTEdit;

You can always get back top that specific one.

Hope that helps..

cheers,

tim

p.s. using the overloaded index [] operator inserts a new item at that
position if it doesn't exist. If that's not the behavior you are
seeking, use find instead.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Remy Lebeau (TeamB)  
View profile
 More options Jul 19 2004, 2:54 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Remy Lebeau \(TeamB\)" <gambit47.no.s...@no.spam.yahoo.com>
Date: Mon, 19 Jul 2004 11:54:56 -0700
Local: Mon, Jul 19 2004 2:54 pm
Subject: Re: How to assign values to several dynamiclay created TEdit's

"Oren Halvani" <NoS...@fdtd.com> wrote in message

news:40fc0556@newsgroups.borland.com...

> OK, i could do it like that:

That is not what I was referring to.  I already showed you how to access
both Left and Right edits given a particular TEdit pointer.  How you get
that pointer to begin with is up to you.

>     std::for_each(Edits.begin(), Edits.end(), ins); // I DO
> NOT NEED ALL EDIT'S..only 7

Then you need to explain - IN DETAIL - exactly what you really want to do.

Gambit


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Remy Lebeau (TeamB)  
View profile
 More options Jul 19 2004, 2:58 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Remy Lebeau \(TeamB\)" <gambit47.no.s...@no.spam.yahoo.com>
Date: Mon, 19 Jul 2004 11:58:55 -0700
Local: Mon, Jul 19 2004 2:58 pm
Subject: Re: How to assign values to several dynamiclay created TEdit's
"Tim Howard" <tim_N0SPAM_@netsimplex_NOSPAM_.com> wrote in message

news:40fc0e58@newsgroups.borland.com...

> First off, you can just do a vector.at( someint ) and
> get just the one you need.

Better to use the '[]' operator instead.

> map< int, TEdit* > someMap;

Since he is giving each TEdit a name, better to use AnsiString or
std::string instead of an int.

    map< AnsiString, TEdit* > someMap;

> someMap[ 1 ] = thisTEdit;

    someMap[ "txtRight" + IntToStr(x) ] = RightEdit;

Or:

    someMap[ RightEdit->Name ] = RightEdit;

Gambit


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Howard  
View profile
 More options Jul 19 2004, 3:22 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: Tim Howard <tim_N0SPAM_@netsimplex_NOSPAM_.com>
Date: Mon, 19 Jul 2004 14:22:35 -0500
Local: Mon, Jul 19 2004 3:22 pm
Subject: Re: How to assign values to several dynamiclay created TEdit's
It's Remy, "The Enforcer", coming to a theatre near you.. To kick your
ass that is.. :) j/k

tim

Remy Lebeau (TeamB) wrote:

  Then you need to explain - IN DETAIL - exactly what you really want to do.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oren Halvani  
View profile
 More options Jul 19 2004, 7:21 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Oren Halvani" <NoS...@fdtd.com>
Date: Tue, 20 Jul 2004 01:21:41 +0200
Local: Mon, Jul 19 2004 7:21 pm
Subject: Re: How to assign values to several dynamiclay created TEdit's

"Remy Lebeau (TeamB)" <gambit47.no.s...@no.spam.yahoo.com>
 schrieb im Newsbeitrag news:40fc18ca$1@newsgroups.borland.com...

> > OK, i could do it like that:
> That is not what I was referring to.  I already showed you how to access
> both Left and Right edits given a particular TEdit pointer.  How you get
> that pointer to begin with is up to you.

but i cannot use pointers.. i need to access them by their names for example:

txtLeft7->Text = "seven"; txtRight7->Text = "seven";
txtLeft11->Text = "eleven"; txtRight11->Text = "eleven";
txtLeft4->Text = "four"; txtRight4->Text = "four";

> >     std::for_each(Edits.begin(), Edits.end(), ins); // I DO
> > NOT NEED ALL EDIT'S..only 7
> Then you need to explain - IN DETAIL - exactly what you really want to do.

dear Remy,

i thought i've done this in the first post...anyway..i've got a ComboBox, that
gives
the user the option to "feed" the dynamicaly created TEdit's with several
values...

BUT how do i access the TEdit's ? Their names are created in the CONSTRUCTOR..
and i need to access them from a TButton->OnClick(...) Event..and of course here
they are unknown...the names that i'm creating here:

__fastcall Form1::Form1(TComponent* Owner) : TForm(Owner)
{
   const int b = 20;  const int width = 110;   const int height = 21;

   Edits.clear();
   int anzahl = 20;

   for(int x = 0; x < anzahl; ++x)
   {
     TEdit *LeftEdit = new TEdit(this);
     LeftEdit->Parent = this;
     LeftEdit->Name = "txtLeft" + IntToStr(x); // NOT GLOBAL...
    //.....

are NOT global, so i cannot access them from Button1->Click(...)

i hope i've explained myself now better..

Oren


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Remy Lebeau (TeamB)  
View profile
 More options Jul 19 2004, 8:09 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Remy Lebeau \(TeamB\)" <gambit47.no.s...@no.spam.yahoo.com>
Date: Mon, 19 Jul 2004 17:09:44 -0700
Local: Mon, Jul 19 2004 8:09 pm
Subject: Re: How to assign values to several dynamiclay created TEdit's

"Oren Halvani" <NoS...@fdtd.com> wrote in message

news:40fc5757@newsgroups.borland.com...

> but i cannot use pointers..

Yes, you can.  Simply look up the pointer that has the name you are looking
for.  You need the pointer in order to actually update the Text.  A pointer
is a pointer regardless of where you get it from.

> i need to access them by their names for example:

You are thinking of the auto-generated pointers that the IDE creates for
you.  You are limiting your thinking too much.

Try this code:

    std::vector<TEdit*> Edits;

    TEdit* __fastcall FindEditByName(const AnsiString &Name)
    {
        std::vector<TEdit*>::iterator iter = Edits.begin();
        while( iter != Edits.end() )
        {
            if( (*iter)->Name == Name )
                return *iter;
        }
        return NULL;
    }

    void __fastcall UpdateEdits(int Number, const AnsiString &Left, const
AnsiString &Right)
    {
        TEdit *pEdit = FindEditByName("txtLeft" + IntToStr(Number));
        if( pEdit )
        {
            reinterpret_cast<TEdit*>(pEdit->Tag) = Left;
            pEdit->Text = Right;
        }
    }

    __fastcall Form1::Form1(TComponent* Owner)
        : TForm(Owner)
    {
        const int b = 20;  const int width = 110;   const int height = 21;

        Edits.clear();
        int anzahl = 20;

        for(int x = 0; x < anzahl; ++x)
        {
            TEdit *LeftEdit = new TEdit(this);
            LeftEdit->Parent = this;
            LeftEdit->Name = "txtLeft" + IntToStr(x);
            //...
            LeftEdit->SetBounds(4, b + (height*x) + 2, width, height);

            TEdit *RightEdit = new TEdit(this);
            RightEdit->Parent = this;
            RightEdit->Name = "txtRight" + IntToStr(x);
            //...
            RightEdit->SetBounds(6 + width, b + (height*x) + 2, width,
height);
            RightEdit->Tag = reinterpret_cast<int>(LeftEdit);

            Edits.push_back(RightEdit);
        }
    }

    void __fastcall Form1::cmdInsert_SampleClick(TObject *Sender)
    {
        switch( Box_Sample->ItemIndex )
        {
            case 0:
                UpdateEdits(0, "Ä", "&Auml;");
                UpdateEdits(1, "Ö", "&Ouml;");
                UpdateEdits(2, "Ü", "&Uuml;");
                UpdateEdits(3, "ä", "&auml;");
                UpdateEdits(4, "ö", "&ouml;");
        &nbs