Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Passing an ArrayList by Reference? [modified]

Passing an ArrayList by Reference? [modified]

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestioncareer
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VonHagNDaz
    wrote on last edited by
    #1

    Hi guys, I'm having a small problem, and I'd like to know what you guys think. User.h:

    void User::getJobs(ArrayList^ jobs)
    {
    jobs = this->jobs;
    }

    UserForm.h:

    UserForm(User^ currentUser)
    {
    InitializeComponent();
    //
    //TODO: Add the constructor code here
    //
    this->user = gcnew User();
    this->allJobs = gcnew ArrayList();

    		Job^ currentJob = gcnew Job();
    		ListViewItem^ item = gcnew ListViewItem();
    
    		this->user = \*currentUser;
    		**_this->user->getJobs(this->allJobs);_**
    
    		for(int i = 0; i < allJobs->Count; i++)
    		{
    			currentJob = (Job^)allJobs\[i\];
    
    			String^ temp = "";
    			currentJob->getCustomerName(temp);
    			item->SubItems->Add(temp);
    
    			temp = "";
    			currentJob->getProjectName(temp);
    			item->SubItems->Add(temp);
    
    			Job::EN\_PRIORITY^ priority = Job::EN\_PRIORITY::EN\_PRIORITY\_0;
    			currentJob->getPriority(priority);
    			switch(\*priority)
    			{
    			case Job::EN\_PRIORITY::EN\_PRIORITY\_0:
    				item->SubItems->Add("NONE");
    				break;
    			case Job::EN\_PRIORITY::EN\_PRIORITY\_1:
    				item->SubItems->Add("1");
    				break;
    			case Job::EN\_PRIORITY::EN\_PRIORITY\_2:
    				item->SubItems->Add("2");
    				break;
    			case Job::EN\_PRIORITY::EN\_PRIORITY\_3:
    				item->SubItems->Add("3");
    				break;
    			case Job::EN\_PRIORITY::EN\_PRIORITY\_4:
    				item->SubItems->Add("4");
    				break;
    			case Job::EN\_PRIORITY::EN\_PRIORITY\_5:
    				item->SubItems->Add("5");
    				break;
    			default:
    				item->SubItems->Add("NONE");
    				break;
    			}
    			listViewAllJobs->Items->Add(item);
    
    			//add time stuff once I figure it out
    		}
    	}
    

    I can see that when getJobs() completes job in Job.h equals the values I'm trying to retrieve, but once the function returns, this->allJobs is blank. Any ideas?

    [Insert Witty Sig Here]

    modified on Friday, May 13, 2011 8:54 AM

    J 1 Reply Last reply
    0
    • V VonHagNDaz

      Hi guys, I'm having a small problem, and I'd like to know what you guys think. User.h:

      void User::getJobs(ArrayList^ jobs)
      {
      jobs = this->jobs;
      }

      UserForm.h:

      UserForm(User^ currentUser)
      {
      InitializeComponent();
      //
      //TODO: Add the constructor code here
      //
      this->user = gcnew User();
      this->allJobs = gcnew ArrayList();

      		Job^ currentJob = gcnew Job();
      		ListViewItem^ item = gcnew ListViewItem();
      
      		this->user = \*currentUser;
      		**_this->user->getJobs(this->allJobs);_**
      
      		for(int i = 0; i < allJobs->Count; i++)
      		{
      			currentJob = (Job^)allJobs\[i\];
      
      			String^ temp = "";
      			currentJob->getCustomerName(temp);
      			item->SubItems->Add(temp);
      
      			temp = "";
      			currentJob->getProjectName(temp);
      			item->SubItems->Add(temp);
      
      			Job::EN\_PRIORITY^ priority = Job::EN\_PRIORITY::EN\_PRIORITY\_0;
      			currentJob->getPriority(priority);
      			switch(\*priority)
      			{
      			case Job::EN\_PRIORITY::EN\_PRIORITY\_0:
      				item->SubItems->Add("NONE");
      				break;
      			case Job::EN\_PRIORITY::EN\_PRIORITY\_1:
      				item->SubItems->Add("1");
      				break;
      			case Job::EN\_PRIORITY::EN\_PRIORITY\_2:
      				item->SubItems->Add("2");
      				break;
      			case Job::EN\_PRIORITY::EN\_PRIORITY\_3:
      				item->SubItems->Add("3");
      				break;
      			case Job::EN\_PRIORITY::EN\_PRIORITY\_4:
      				item->SubItems->Add("4");
      				break;
      			case Job::EN\_PRIORITY::EN\_PRIORITY\_5:
      				item->SubItems->Add("5");
      				break;
      			default:
      				item->SubItems->Add("NONE");
      				break;
      			}
      			listViewAllJobs->Items->Add(item);
      
      			//add time stuff once I figure it out
      		}
      	}
      

      I can see that when getJobs() completes job in Job.h equals the values I'm trying to retrieve, but once the function returns, this->allJobs is blank. Any ideas?

      [Insert Witty Sig Here]

      modified on Friday, May 13, 2011 8:54 AM

      J Offline
      J Offline
      John Schroedl
      wrote on last edited by
      #2

      If you are expecting getJobs() to change the incoming 'jobs' parameter to reference a different ArrayList even after the function returns, you'll need to use a "tracking reference". To do that use the % decoration and declare the function like this:

      void User::getJobs(ArrayList^% jobs)
      {
      jobs = this->jobs;
      }

      An alternative would be to loop and copy all the items from this->jobs into jobs. John

      V 1 Reply Last reply
      0
      • J John Schroedl

        If you are expecting getJobs() to change the incoming 'jobs' parameter to reference a different ArrayList even after the function returns, you'll need to use a "tracking reference". To do that use the % decoration and declare the function like this:

        void User::getJobs(ArrayList^% jobs)
        {
        jobs = this->jobs;
        }

        An alternative would be to loop and copy all the items from this->jobs into jobs. John

        V Offline
        V Offline
        VonHagNDaz
        wrote on last edited by
        #3

        That did the trick! I'm new to managed code and c++/CLI. All of these new operators are throwing me for a loop. Darn Windows forms projects!

        [Insert Witty Sig Here]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups