Returning rowIDs of selected objects

1,114 views
Skip to first unread message

Matt

unread,
Jan 18, 2007, 12:39:55 AM1/18/07
to MapInfo-L
I am writing a script in MapBasic, and have need to get all of the
rowIDs for each of a bunch of selected objects. I need their rowIDs
from their original, source table, not from the temporary "Selection"
table that is created when objects are selected.

originalTable.rowID returns the rowID of the first selected object, in
the originalTable, which is what I want. Unfortunately, I can't get it
to return more than the first, and additionally, I don't always know
which table the selection is being made on (I can find out using
SelectionInfo(SEL_INFO_TABLENAME), but how do I query tableName.rowID,
when "tableName" is a string returned from a function?).

I'm stuck. Real stuck.

Matt

Llewellyn, David

unread,
Jan 18, 2007, 12:52:14 AM1/18/07
to mapi...@googlegroups.com

Hi Matt,

It sounds as though you need an 'Alias' variable.

You could append ".rowID" to your return value string and store that in
your alias variable to reference the value of that column.

David

Matt


If this email has been received in error, please delete all copies and inform the National Native Title Tribunal by return email or telephone 1800 640 501. The Tribunal does not warrant that its email is virus free. All emails sent to the Tribunal are filtered for viruses and inappropriate content. Thus your email may not reach the person to whom it is addressed. Seek confirmation of receipt of your email if you consider the email important.

Matt

unread,
Jan 18, 2007, 1:05:20 AM1/18/07
to MapInfo-L
Well, what do you know?

I didn't even realise there was a type called "alias". That helps out a
lot. A massive amount, actually.

Matt

unread,
Jan 18, 2007, 1:23:51 AM1/18/07
to MapInfo-L
Actually, that isn't the whole story.

Using A Fetch First / Fetch Next loop doesn't seem to cycle through the
rowIDs. It does cycle through the Selection.rowIDs, but not through the
originalTable.rowIDs.

Martin R

unread,
Jan 18, 2007, 2:31:44 AM1/18/07
to MapInfo-L
Hi Matt,

The only way I am aware of is by using the SelChangedHandler and
CommandInfo(CMD_INFO_ROWID).

This however means selecting every record in the query and therefore
may be a bit cumbersome - not to mention annoying to the user to see
everything flash.

As an example the following code will print the original rowid of the
records in a query called tmp

-----------------------------------------------------------------------------------------------------------------------------
Include "mapbasic.def"
Declare Sub Main
Declare Sub SelChangedHandler

Dim i as integer
Dim j as integer
Dim sTab as string
Sub Main
sTab = "tmp" '<-- the name of the Query you want hte ID's for
j = tableinfo(tmp,tab_info_nrows)
for i = 1 to j
select * from tmp where rowid = i into xxTmp
next
end sub
Sub SelChangedHandler
if SelectionInfo(SEL_INFO_NROWS) = 1 then
print "The recod in row " & i & " of Query "
& stab & " is from row "
& CommandInfo(CMD_INFO_ROWID)
& " of table "
& selectioninfo(SEL_INFO_TABLENAME)
end if
end sub
-----------------------------------------------------------------------------------------------------------------------------


Hope this helps

Regards

Martin

Darren Chan

unread,
Jan 18, 2007, 9:44:47 AM1/18/07
to mapi...@googlegroups.com
G'day Matt...

It is interesting that you mention obtaining only the first tablename.
Within MapInfo, although several tables may be enabled for selection in
Layer Control, I found that only objects of one table are able to be
selected in a group.

You may have better control creating your own toolbutton and using functions
SearchPoint() or SearchRectangle() followed by SearchInfo() if you wish to
determine the objects found at a location selected the user.

Rgds
Darren

-----Original Message-----
From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On
Behalf Of Matt
Sent: Thursday, January 18, 2007 12:40 AM
To: MapInfo-L
Subject: [MI-L] Returning rowIDs of selected objects

Matt

unread,
Jan 18, 2007, 7:30:26 PM1/18/07
to MapInfo-L
Fantastic.

I did a bit of experimenting. It is the CommandInfo(CMD_INFO_ROWID)
that does the trick. No need to use the SelChangedHandler. In fact, it
is better not to, because it is called when something is deselected,
and CommandInfo(CMD_INFO_ROWID) can also return the last deselected
rowID.

Just put CommandInfo(CMD_INFO_ROWID) into the main loop.

Reply all
Reply to author
Forward
0 new messages