English

How To: Keep certain tables from being edited in a project [SCRIPT]

Procedure

Question:

How to prevent certain tables in a project from being edited.

Answer:

The following sample code keeps selected tables from being edited. There are three scripts that are set into the project file. Two of them are set to the click/update events for a new button that must be created on the Table bar. The "locking" is actually disabling the editing function for certain tables.

'------ Start Script 1
'--- This script sets a global variable for the other two scripts to use.
'--- Set this script as an Update script under the Project GUI.
'--- Create a new menu choice for this task and make it invisible.

_locklist=nil

'------ End Of Script 1

'------ Start Script 2
'--- This script gets the tables you wish to keep from editing. Each locked table will
'-- be tagged with the string "locked"
'--- Set this script as the Click event.
'--- Create a new button in the button bar for this task.

_lockList={}

x=99
while (x=99)
aFile=msgbox.input("Name of table to Lock:", "Lock Box","")
aDoc=av.GetProject.FindDoc(aFile.AsString)
if (aFile = nil) then
exit
elseif (aDoc=nil) then
msgbox.info
("Table "+aFile++"does not exist, try again","Table doesn't exist")
else
_lockList.Add(aFile) 'adds your table names as strings to a list
Yn=msgbox.MiniYesNo("Do you wish to add another table?", false)
if (Yn = false) then
x=nil
end
end
end

msgbox.listAsString(_locklist, "Your Locked files","")

for each i in _locklist
av.GetProject.FindDoc(i).SetObjectTag("locked")
end

'------ End Of Script 2

'------ Start Script 3
'--- This script searches for the tables that are to be kept from editing and locks
'-- them out.
'--- Set this script as the Update event for the new button that should have
'-- been created earlier.

aDoc=av.getactivedoc
theMenu=av.GetActiveGui.GetMenuBar.GetControls.Get(2)
aChoice=theMenu.FindByLabel("Start &Editing")

if (aDoc.GetObjectTag="Locked") then
aChoice.SetVisible(false)
elseif (aDoc.GetObjectTag=nil) then
aChoice.SetVisible(true)
end

'------ End Of Script 3