Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 3 of 3

For Each with c++ ?

This is a discussion on For Each with c++ ? within the MapPoint Desktop Discussion forums, part of the Map Forums category; I have some C# code I am trying to convert to C++: Code: foreach (MapPoint.DataSet ods in map.DataSets) { // ...

  1. #1
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    For Each with c++ ?

    I have some C# code I am trying to convert to C++:

    Code:
     
                foreach (MapPoint.DataSet ods in map.DataSets)
                {
                   // Do some stuff
                }
    What should this look like in C++ ? Can I use a "for each" or do I need to iterate another way?

    Thanks!
    Eric

  2. #2
    eric.hill is offline Junior Member White Belt
    Join Date
    Apr 2006
    Posts
    5

    Re: For Each with c++ ?

    Code:
    MapPoint::DataSetsPtr dset_ = map->GetDataSets();
    MapPoint::DataSets* dset = dset_;
    	
    for (int i = 0; i < dset->Count; i++) {
    	MapPoint::DataSet* ds;
    	ds = dset->Item[&_variant_t(i)];
    	// ds->Something;
    }

  3. #3
    Eric Frost's Avatar
    Eric Frost is offline Administrator Black Belt
    Join Date
    Jul 1992
    Posts
    5,094
    Blog Entries
    4

    Re: For Each with c++ ?

    I found a work-around so I don't actually need to do this in my code anymore.

    Eric, I did try your code and got an error, I suspect because of the int i = 0. I think with MapPoint it starts at 1.

    Alex Feinman in a VC++ newsgroup suggested this, I haven't tried it but just thought I would share. Notice the LONG i = 1 --

    Code:
     
    #include "stdafx.h"
    #import "progid:MapPoint.Application" rename("EOF", "_EOF"), no_namespace
    
    int _tmain(int argc, _TCHAR* argv[])
    {
     CoInitializeEx(NULL, COINIT_MULTITHREADED);
     {
      _ApplicationPtr pApp;
      HRESULT hr = pApp.CreateInstance(__uuidof(Application));
      _MapPtr pMap = pApp->OpenMap(_bstr_t("e:\\TestMap.ptm"), VARIANT_FALSE);
      DataSetsPtr pDatasets = pMap->DataSets;
      for( LONG i = 1; i <= pDatasets->Count; i++ )
      {
       _variant_t v(i);
       DataSetPtr pItem = pDatasets->Item[&v];
        _tprintf(_T("%s\r\n"), (LPCTSTR)pItem->Name);
      }
      pMap->PutSaved(VARIANT_TRUE);
     }
     CoUninitialize();
     return 0;
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66