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 5 of 5

Locating the name of a Shape selected

This is a discussion on Locating the name of a Shape selected within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hello I'm trying to find the name of a shape by clicking on it. I've succesfully created an event when ...

  1. #1
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137

    Locating the name of a Shape selected

    Hello

    I'm trying to find the name of a shape by clicking on it.

    I've succesfully created an event when the mouse pointer is on the shape by using the "SelectionChange" event, but how do I find the name of the shape I've just selected, so it's ready to place into a string variable.

    The code I used to select the shape is shown below: -

    procedure TMainForm.MappointSelectionChange(Sender: TObject; const pNewSelection, pOldSelection: IDispatch);
    var
    oShape: Shape;
    begin
    If assigned(pNewSelection) Then
    Begin
    pNewSelection.QueryInterface(IID_Shape, oShape);
    If assigned(oShape) Then
    Begin
    Showmessage('Its a Shape');
    // Now I need the name of the shape !!!!!!
    End;
    End;
    end;

    Note, I'm not using a commercial database, and have not imported data, I'm using my own comma delimited data to add the shapes.

    Each shape has a name representing its place in the database. i.e. a number converted into a string.

    I'm using Delphi but do understand VB (slightly), so any help in either language would be of great benefit.

    Thank you

    Regards
    Les

  2. #2
    John Meyer's Avatar
    John Meyer is offline Senior Member Blue Belt
    Join Date
    Jul 2002
    Posts
    478
    Here is a vb example, hope it helps you...

    Code:
    Dim objApp As New MapPoint.Application
    Dim objMap As MapPoint.Map
    Dim objLoc As MapPoint.Location
    Dim objShape As MapPoint.Shape
      'Set up application and get a location object
    Set objMap = objApp.ActiveMap
    objApp.Visible = True
    objApp.UserControl = True
      Set objLoc = objApp.ActiveMap.GetLocation(0, 0)
    
    'Create a shape at this location, zoom to this location
    Set objMap.Location = objLoc
    Set objShape = objMap.Shapes.AddShape(geoShapeRectangle, objLoc, 50, 30)
    objShape.Name = "Test123"
    MsgBox objShape.Name

  3. #3
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    Thanks for the code John, but I'm not sure it does the required task.

    Looking at the code, it seems to be simply placing a shape and displaying it's name.

    I may be wrong on this, as I find VB syntax very confusing. The part I'm not sure about is the fist block of code: -

    'Set up application and get a location object
    Set objMap = objApp.ActiveMap
    objApp.Visible = True
    objApp.UserControl = True
    Set objLoc = objApp.ActiveMap.GetLocation(0, 0)

    What exactly is this doing?

    Thank you

    Regards
    Les

  4. #4
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    Examining the code more closely, it does seem as though it is simply finding a location at coord 0,0, then placing an object, then retreiving it's name.

    What i'm trying to accomplish (with very little headway) is the name of a shape previously placed on the map, simply by selecting it with the mouse pointer.

    Selecting the shape and recognising it is a shape was relatively straightforward, but I simply cannot find anything in the help or the MSDN that is of any relevance to a shape. Pushpin yes, shape No!

    Regards
    Les

  5. #5
    Anonymous is offline Senior Member Black Belt
    Join Date
    Jul 2002
    Posts
    5,137
    Hello John

    You know when you can't see the wood for the trees, well I've just had that experience.

    You're code pushed me in the right direction.

    I now realise that selecting a shape using the mouse pointer is exacly the same as issuing the .SELECT command. So once it's selected, the .NAME command can be issued. It's so simple once the penny drops.

    So for anyone out there using Delphi and wanting to find the name of a shape when selecting with a mouse, here's a procedure that will accomplish it.

    Code:
    procedure TMainForm.MappointSelectionChange(Sender: TObject; const pNewSelection, pOldSelection: IDispatch); 
    var 
        oShape: Shape; 
    begin 
        If assigned(pNewSelection) Then 
          Begin 
            pNewSelection.QueryInterface(IID_Shape, oShape); 
            If assigned(oShape) Then Showmessage('Shape Name = ' + oShape.Name); 
          End; 
    end;
    Thanks ever so much for the push in the right direction.

    Regards
    Les

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Does an object reside in my Shape or Shape boundaries?
    By hotrdd in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 08-04-2005, 10:51 PM
  2. Newbie Question: Locating golf courses around pushpins?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 06-07-2004, 09:27 AM
  3. Locating pushpins w/in specific distance
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 12-19-2003, 06:07 PM
  4. Pl.. Help ----Locating/ placing positions in India
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 11-13-2003, 03:20 AM
  5. Locating pushpin with partial name
    By Dazzer in forum MapPoint Desktop Discussion
    Replies: 5
    Last Post: 10-27-2003, 06:01 AM

Tags for this Thread

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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96