Locating the name of a Shape selected

Anonymous
04-29-2004, 06:32 AM
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

John Meyer
04-29-2004, 02:19 PM
Here is a vb example, hope it helps you...

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

Anonymous
04-30-2004, 03:09 AM
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

Anonymous
04-30-2004, 03:23 AM
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

Anonymous
04-30-2004, 04:57 AM
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.


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

 
Web mp2kmag.com
mapforums.com