Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restructuring Tables from a PushButton??

Status
Not open for further replies.

SercoSteve

Programmer
Sep 25, 2002
44
GB
Hi

I have two tables partslist_dev1.DB and partslist_dev2.DB. The tables are copies of each other with one modification made to partslist_dev2.DB. The modification being Partslist_dev2.DB contains a Table Lookup to another table referenced using an ALIAS.

I am attempting to modify the structure of partslist_dev1.DB to that of partslist_dev2.DB from a pushbutton using the code shown below, can anyone see what I am doing wrong as the Restructure always returns FALSE.

var
custTbl Table
modifiedTbl Table
dynNewStru DynArray[] Anytype
endVar

custTbl.attach(":pRIV:partslist_dev2.DB")
if custTbl.isTable() then
custTbl.enumFieldStruct(":pRIV:newstructure.DB")
custTbl.unattach()
if modifiedTbl.attach(":pRIV:partslist_dev1.DB") then
if modifiedTbl.isTable() then
dynNewStru["FIELDSTRUCT"] = ":pRIV:newstructure.DB"
if modifiedTbl.restructure( dynNewStru ) then
custTbl.unattach()
moveTo(plist)
endIf
endIf
endIf
endIf

Thanks in advance

Steve
 
Is :pRIV:partslist_dev1.DB open, either from another form, report, tcursor, etc? restructure requires a full lock on the table. You could test by attempting a full lock explicitly (and then releasing it) e.g.
if modifiedTbl.attach(":pRIV:partslist_dev1.DB") then
if modifiedTbl.isTable() then
if modifiedTbl.lock("Full") then
modifiedTbl.unlock("Full")
else
msgStop("", "Can't lock destination table")
return
endif
dynNewStru["FIELDSTRUCT"] = ":pRIV:newstructure.DB"
if modifiedTbl.restructure( dynNewStru ) then
custTbl.unattach()
moveTo(plist)
endIf
endIf
endIf

or you could use lockStatus() method to return the number of locks.
 
Thanks for you reply.

Yeah... I've been down that road today. I can lock("FULL") on partslist_dev1.DB ok.

Been doing some investigation of my own and Restructure doesn't seem to like Keys or Table Lookups, if I remove both I can get the Restructure to work ok.

Also can you believe Example 1 (see below) doesn't work and Example 2 does.

Example 1
custTbl.attach(":pRIV:partslist_temp.DB")
if custTbl.isTable() then
custTbl.enumFieldStruct(":pRIV:newstructure.DB")
custTbl.unattach()
if modifiedTbl.attach(":pRIV:partslist.DB") then
if modifiedTbl.isTable() then
dynNewStru["FIELDSTRUCT"] = ":pRIV:newstructure.DB"
if modifiedTbl.restructure( dynNewStru ) then
moveTo(plist)
endIf
endIf
endIf
endIf

Example 2
custTbl.attach(":pRIV:partslist_temp.DB")
if custTbl.isTable() then
custTbl.enumFieldStruct(":pRIV:newstructure.DB")
custTbl.unattach()
if modifiedTbl.attach("c:\\Corel\\Suite8\\Paradox\\Private\\partslist.DB") then
if modifiedTbl.isTable() then
dynNewStru["FIELDSTRUCT"] = ":pRIV:newstructure.DB"
if modifiedTbl.restructure( dynNewStru ) then
moveTo(plist)
endIf
endIf
endIf
endIf

The only thing I changed was to remove the ALIAS on the Table Attach for the table to be modified, replacing it with the full path.

Aliasing Madness

Steve

 
Yep. I've had the ALIAS vs path one before, especially with filesystem methods. I use getAliasPath() a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top