2个回答
展开全部
用mapbasic把下面这段代码copy,只需要修改标识的部分就可以了。
include "MapBasic.def"
include "ICONS.DEF"
include "menu.def"
Declare sub main
Declare sub Mcopy
Declare sub Mpaste
'下面的结构体要修改成跟你的表结构一致
Type RowRecord
id As integer
age As float
name As String
End Type
’以上修改
Global r_copy As RowRecord
sub main
Create ButtonPad "Utils" As
ToolButton
HelpMsg "Choose this button to display query dialog"
Calling Mcopy ID 1
Icon MI_ICON_COPY
DrawMode DM_CUSTOM_POINT
ToolButton
HelpMsg "Use this tool to draw a new route"
Calling Mpaste ID 2
Icon MI_ICON_PASTE
DrawMode DM_CUSTOM_POINT
Title "Utilities"
Width 2
Show
end sub
sub Mcopy
Dim x, y, x2, y2 As Float,
i, i_found, i_row_id, i_win_id As Integer,
s_table As Alias
i_win_id = FrontWindow()
If WindowInfo(i_win_id, WIN_INFO_TYPE) <> WIN_MAPPER Then
Note "This tool only works on Map windows."
Exit Sub
End If
' Determine the starting point where the user clicked.
x = CommandInfo(CMD_INFO_X)
y = CommandInfo(CMD_INFO_Y)
If CommandInfo(CMD_INFO_TOOLBTN) = 1 Then
' Then the user is using the point-mode tool.
' determine how many objects are at the chosen point.
i_found = SearchPoint(i_win_id, x, y)
Else
' The user is using the rectangle-mode tool.
' Determine what objects are within the rectangle.
x2 = CommandInfo(CMD_INFO_X2)
y2 = CommandInfo(CMD_INFO_y2)
i_found = SearchRect(i_win_id, x, y, x2, y2)
End If
If i_found = 0 Then
Beep ' No objects found where the user clicked.
Else
Print Chr$(12)
If CommandInfo(CMD_INFO_TOOLBTN) = 2 Then
Print "Rectangle: x1= " + x + ", y1= " + y
Print "x2= " + x2 + ", y2= " + y2
Else
Print "Point: x=" + x + ", y= " + y
End If
' Process the search results.
For i = 1 to i_found
' Get the name of the table containing a "hit".
s_table = SearchInfo(i, SEARCH_INFO_TABLE)
' note s_table
' Get the row ID number of the object that was a hit.
i_row_id = SearchInfo(i, SEARCH_INFO_ROW)
If Left$(s_table, 8) = "Cosmetic" Then
Print "Object in Cosmetic layer"
Else
' Fetch the row of the object the user clicked on.
Fetch rec i_row_id From s_table
'下面要修改,改成跟你表结构一样的列名字,列的数目也要一致
s_table = SearchInfo(i, SEARCH_INFO_TABLE)
s_table = s_table + ".col1"
r_copy.id = s_table
s_table = SearchInfo(i, SEARCH_INFO_TABLE)
s_table = s_table + ".col2"
r_copy.age = s_table
s_table = SearchInfo(i, SEARCH_INFO_TABLE)
s_table = s_table + ".col3"
r_copy.name = s_table
'以上
Print "复制完毕"
End If
Next
End If
end sub
sub Mpaste
Dim x, y, x2, y2 As Float,
i, i_found, i_row_id, i_win_id As Integer,
s_table As Alias
i_win_id = FrontWindow()
If WindowInfo(i_win_id, WIN_INFO_TYPE) <> WIN_MAPPER Then
Note "This tool only works on Map windows."
Exit Sub
End If
' Determine the starting point where the user clicked.
x = CommandInfo(CMD_INFO_X)
y = CommandInfo(CMD_INFO_Y)
If CommandInfo(CMD_INFO_TOOLBTN) = 2 Then
' Then the user is using the point-mode tool.
' determine how many objects are at the chosen point.
i_found = SearchPoint(i_win_id, x, y)
Else
' The user is using the rectangle-mode tool.
' Determine what objects are within the rectangle.
x2 = CommandInfo(CMD_INFO_X2)
y2 = CommandInfo(CMD_INFO_y2)
i_found = SearchRect(i_win_id, x, y, x2, y2)
End If
If i_found = 0 Then
Beep ' No objects found where the user clicked.
Else
Print Chr$(12)
If CommandInfo(CMD_INFO_TOOLBTN) = 1 Then
Print "Rectangle: x1= " + x + ", y1= " + y
Print "x2= " + x2 + ", y2= " + y2
Else
Print "Point: x=" + x + ", y= " + y
End If
' Process the search results.
For i = 1 to i_found
' Get the name of the table containing a "hit".
s_table = SearchInfo(i, SEARCH_INFO_TABLE)
' Get the row ID number of the object that was a hit.
i_row_id = SearchInfo(i, SEARCH_INFO_ROW)
If Left$(s_table, 8) = "Cosmetic" Then
Print "Object in Cosmetic layer"
Else
' Fetch the row of the object the user clicked on.
Fetch rec i_row_id From s_table
'以下要修改,结构跟表结构一样
Update s_table Set col1 = r_copy.id
Where RowID = i_row_id
Update s_table Set col2=r_copy.age
Where RowID = i_row_id
Update s_table Set col3=r_copy.name
Where RowID = i_row_id
'以上
End If
Next
End If
end sub
include "MapBasic.def"
include "ICONS.DEF"
include "menu.def"
Declare sub main
Declare sub Mcopy
Declare sub Mpaste
'下面的结构体要修改成跟你的表结构一致
Type RowRecord
id As integer
age As float
name As String
End Type
’以上修改
Global r_copy As RowRecord
sub main
Create ButtonPad "Utils" As
ToolButton
HelpMsg "Choose this button to display query dialog"
Calling Mcopy ID 1
Icon MI_ICON_COPY
DrawMode DM_CUSTOM_POINT
ToolButton
HelpMsg "Use this tool to draw a new route"
Calling Mpaste ID 2
Icon MI_ICON_PASTE
DrawMode DM_CUSTOM_POINT
Title "Utilities"
Width 2
Show
end sub
sub Mcopy
Dim x, y, x2, y2 As Float,
i, i_found, i_row_id, i_win_id As Integer,
s_table As Alias
i_win_id = FrontWindow()
If WindowInfo(i_win_id, WIN_INFO_TYPE) <> WIN_MAPPER Then
Note "This tool only works on Map windows."
Exit Sub
End If
' Determine the starting point where the user clicked.
x = CommandInfo(CMD_INFO_X)
y = CommandInfo(CMD_INFO_Y)
If CommandInfo(CMD_INFO_TOOLBTN) = 1 Then
' Then the user is using the point-mode tool.
' determine how many objects are at the chosen point.
i_found = SearchPoint(i_win_id, x, y)
Else
' The user is using the rectangle-mode tool.
' Determine what objects are within the rectangle.
x2 = CommandInfo(CMD_INFO_X2)
y2 = CommandInfo(CMD_INFO_y2)
i_found = SearchRect(i_win_id, x, y, x2, y2)
End If
If i_found = 0 Then
Beep ' No objects found where the user clicked.
Else
Print Chr$(12)
If CommandInfo(CMD_INFO_TOOLBTN) = 2 Then
Print "Rectangle: x1= " + x + ", y1= " + y
Print "x2= " + x2 + ", y2= " + y2
Else
Print "Point: x=" + x + ", y= " + y
End If
' Process the search results.
For i = 1 to i_found
' Get the name of the table containing a "hit".
s_table = SearchInfo(i, SEARCH_INFO_TABLE)
' note s_table
' Get the row ID number of the object that was a hit.
i_row_id = SearchInfo(i, SEARCH_INFO_ROW)
If Left$(s_table, 8) = "Cosmetic" Then
Print "Object in Cosmetic layer"
Else
' Fetch the row of the object the user clicked on.
Fetch rec i_row_id From s_table
'下面要修改,改成跟你表结构一样的列名字,列的数目也要一致
s_table = SearchInfo(i, SEARCH_INFO_TABLE)
s_table = s_table + ".col1"
r_copy.id = s_table
s_table = SearchInfo(i, SEARCH_INFO_TABLE)
s_table = s_table + ".col2"
r_copy.age = s_table
s_table = SearchInfo(i, SEARCH_INFO_TABLE)
s_table = s_table + ".col3"
r_copy.name = s_table
'以上
Print "复制完毕"
End If
Next
End If
end sub
sub Mpaste
Dim x, y, x2, y2 As Float,
i, i_found, i_row_id, i_win_id As Integer,
s_table As Alias
i_win_id = FrontWindow()
If WindowInfo(i_win_id, WIN_INFO_TYPE) <> WIN_MAPPER Then
Note "This tool only works on Map windows."
Exit Sub
End If
' Determine the starting point where the user clicked.
x = CommandInfo(CMD_INFO_X)
y = CommandInfo(CMD_INFO_Y)
If CommandInfo(CMD_INFO_TOOLBTN) = 2 Then
' Then the user is using the point-mode tool.
' determine how many objects are at the chosen point.
i_found = SearchPoint(i_win_id, x, y)
Else
' The user is using the rectangle-mode tool.
' Determine what objects are within the rectangle.
x2 = CommandInfo(CMD_INFO_X2)
y2 = CommandInfo(CMD_INFO_y2)
i_found = SearchRect(i_win_id, x, y, x2, y2)
End If
If i_found = 0 Then
Beep ' No objects found where the user clicked.
Else
Print Chr$(12)
If CommandInfo(CMD_INFO_TOOLBTN) = 1 Then
Print "Rectangle: x1= " + x + ", y1= " + y
Print "x2= " + x2 + ", y2= " + y2
Else
Print "Point: x=" + x + ", y= " + y
End If
' Process the search results.
For i = 1 to i_found
' Get the name of the table containing a "hit".
s_table = SearchInfo(i, SEARCH_INFO_TABLE)
' Get the row ID number of the object that was a hit.
i_row_id = SearchInfo(i, SEARCH_INFO_ROW)
If Left$(s_table, 8) = "Cosmetic" Then
Print "Object in Cosmetic layer"
Else
' Fetch the row of the object the user clicked on.
Fetch rec i_row_id From s_table
'以下要修改,结构跟表结构一样
Update s_table Set col1 = r_copy.id
Where RowID = i_row_id
Update s_table Set col2=r_copy.age
Where RowID = i_row_id
Update s_table Set col3=r_copy.name
Where RowID = i_row_id
'以上
End If
Next
End If
end sub
参考资料: mapbasic帮助
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |