locked
[VSC++]Why don't work ? RRS feed

  • Question

  • Hi,
    I wrote class with  function  for display object (my class )name, this is this  function:

    String  ^Kadlub::wypisz(){
            String ^wsk_nazwa;
            wsk_nazwa = gcnew String("");

            for(unsigned int i=0; i < nazwa.length(); i++){
                    wsk_nazwa = wsk_nazwa + Convert::ToChar(nazwa.data()[i]);
            }

    return wsk_nazwa;

    };
    and my  class:

    class Kadlub{
        public:
            string nazwa;
            double wytrzymalosc;
            double granica;
            double wydluzenie;
            double twardosc;
            double gestosc;
            Kadlub(string nazw,double wytr, double gran, double wydl, double twar ,double gest);
            Kadlub();
            ~Kadlub();
        String ^wypisz();
        };


    and next i  have a table with  my objects,
    im  search  object  in my table, and display  the name of this objects.

    and now:
    when im use MessageBox  for display search result  ,  function display  all  objects, when they is OK,
    but when i  want  display all searched result (objects name)  with  my  function (wypisz(); )  i can display only first object.
    why?


    this is my  code:


    for(unsigned int count =0; count<ile_kadlubow; count++){
                            if(tablica_kadlubow[count].wytrzymalosc >=min && tablica_kadlubow[count].wytrzymalosc<=max)
                                                       
                                MessageBox::Show("nazwa :" + tablica_kadlubow[count].wytrzymalosc );                                              //MessageBox  display all  search result,  its OK
                                label21->Text= (Convert::ToString(tablica_kadlubow[count].wypisz()));
                                // this display only first  object :(
                               
                        }





    Monday, March 9, 2009 7:45 AM

Answers

  • Does this solve the problem?

     

    String ^ text = "";  
     
    for(unsigned int count = 0; count < ile_kadlubow; count++)  
    {  
        if(tablica_kadlubow[count].wytrzymalosc >= min && tablica_kadlubow[count].wytrzymalosc <= max)  
        {  
            MessageBox::Show("nazwa :" + tablica_kadlubow[count].wytrzymalosc );  
            text += tablica_kadlubow[count].wypisz() + " ";  
        }  
    }  
     
    label21->Text = text;  
     
     

     

    Note that conversion from std::string to String probably can be done easier with Marshal::PtrToStringAnsi function.

    • Marked as answer by msdn_2009 Monday, March 9, 2009 8:34 AM
    Monday, March 9, 2009 8:11 AM

All replies

  • Does this solve the problem?

     

    String ^ text = "";  
     
    for(unsigned int count = 0; count < ile_kadlubow; count++)  
    {  
        if(tablica_kadlubow[count].wytrzymalosc >= min && tablica_kadlubow[count].wytrzymalosc <= max)  
        {  
            MessageBox::Show("nazwa :" + tablica_kadlubow[count].wytrzymalosc );  
            text += tablica_kadlubow[count].wypisz() + " ";  
        }  
    }  
     
    label21->Text = text;  
     
     

     

    Note that conversion from std::string to String probably can be done easier with Marshal::PtrToStringAnsi function.

    • Marked as answer by msdn_2009 Monday, March 9, 2009 8:34 AM
    Monday, March 9, 2009 8:11 AM
  • Thanks!
    Now It's work fine.

    Monday, March 9, 2009 8:34 AM