Hi Quang,
you now posted this script for the fourth time in different threads!
I don't think that repetition will raise the chance for an answer!
You received a couple of hints alreaday but you do not seem to care
1. I proposed to put all your scripts into the script of your MAIN stack. so all other stacks/cards/objects can use these scripts
2. Then someone else proposed that you make your substack with the relevant scripts a LIBRARY stack, which is obviously what you need here.
3. Someone else pointed out that you do definitvely NOT need to use "call" at all here, which does not work at all anyway.
No reaction from you, but the same question(s) again.
OK, I will give it another try, but please read this carefully and try to understand what we are porposing!
And look up every unknown (or uncertain!) term in the LiveCode dictionary!
And work through all the stack we already posted links to!
1. To make you substack a REAL library stack, in the true meaning of the word, you do this:
Add this handler to your mainstack script, maybe "on openstack"
Code: Select all
on openstack
## Your stuff here
## ..
start using "Nmae of your substack with all the handlers and functions!
end openstack
Now ALL stack (main or sub) and all cards and all objects on all cards in all stack can access the script of your substack/library stack!
AND now there is no need for "CALL" anymore", so you can simply:
Code: Select all
on mouseUp
## call openConnection of card "DBConnection" of stack "Mysubstack" ==call command from substack
## Not neccessary anymore! Instead use:
openConnection
...
2. You use:
...
private command ConvertSQLCursorToArray pCursor, @pOutArrayA
## ???
...
a. PRIVATE does not make sense and is wrong in this contexthere, so don't use it!
b. @pOutArrayA: this means hat you are going to PASS a value BY REFERENCE, but you don't.
If you do not understand what the @ sign (pass by reference) means, then don't use it!
Turn this handler into a function it will work:
Code: Select all
function ConvertSQLCursorToArray pCursor
local i
local theFields
local theError
## Get the names of all the columns in the database cursor
put revDatabaseColumnNames(pCursor) into theFields
put empty into pOutArrayA
## Any problems? Then get out of here!
if theFields begins with "revdberr," then
answer "AN error occured:" & CR & item 2 to -1 of theFields i
EXIT to top
end if
put 0 into i
## Loop through all rows in cursor
repeat until revQueryIsAtEnd(pCursor)
add 1 to i
## Move all fields in row into next dimension of the array
repeat for each item theField in theFields
put revDatabaseColumnNamed(pCursor, theField) into pOutArrayA[i][ theField ]
end repeat
revMoveToNextRecord pCursor
end repeat
return pOutArrayA
end ConvertSQLCursorToArray
c. Now you can use this anyhwere in your stacks like:
Code: Select all
on mouseUp
## No need to CALL anything anymore!
openConnection
global gConnectionID
if gConnectionID is a integer then
## Query the database for data
put revQueryDatabase( gConnectionID, "call test1()") into theCursor
## I am not sure what "call test1()" is meant to do here?
if theCursor is an integer then
PUT ConvertSQLCursorToArray(theCursor) into theDataGridArray
### etc...
...
So please try our solutions and check if that will work for you, which we are sure of!
Best
Klaus