I'm developing a code library that can be reused in any card and stack. There are 1 stack and 1 substack, just for you have more understand what I'm doing

*Stack is Application
-Test card : there is 1 button to select record into datagrid
*substack is MyLibrary
-DBConnection card : there are 3 command
-openConnection
-CloseConnection
-ConvertCursortoArray
My problem is not able to call ConvertCursortoArray but I can call openConnection.
I have try to fix but It doesn't help.Hope you guys can help me
Here is my code
*substack
#################################################################################################################################
on openConnection
-- use a global variable to hold the connection ID so other scripts can use it
global gConnectionID
-- set up the connection parameters - edit these to suit your database
put "localhost" into tDatabaseAddress
put "quangtemp" into tDatabaseName
put "root" into tDatabaseUser
put "1234567" into tDatabasePassword
-- connect to the database
put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
if tResult is a number then
put tResult into gConnectionID
#answer info "Connected to the database." & cr & "Connection ID = " & gConnectionID
else
put empty into gConnectionID
answer error "Unable to connect to the database:" & cr & tResult
end if
end openConnection
#################################################################################################
on closeConnection
global gConnectionID
-- if we have a connection, close it and clear the global connection ID
if gConnectionID is a number then
revCloseDatabase gConnectionID
put empty into gConnectionID
end if
end closeConnection
##################################################################################################
public command ConvertSQLCursorToArray pCursor, @pOutArrayA
local i
local theFields
local theError
## Get the names of all the columns in the database cursor
put revDatabaseColumnNames(pCursor) into theFields
if theFields begins with "revdberr," then
put item 2 to -1 of theFields into theError
end if
if theError is empty then
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[ theField ]
end repeat
revMoveToNextRecord pCursor
end repeat
end if
return theError
end ConvertSQLCursorToArray
################################################################################################
* myStack Application
on mouseUp
call openConnection of card "DBConnection" of stack "Mysubstack"
global gConnectionID
if gConnectionID is a integer then
## Query the database for data
put revQueryDatabase( gConnectionID, "call test1()") into theCursor
if theCursor is an integer then
call ConvertSQLCursorToArray theCursor, theDataGridArray ======================PROBLEM IS HERE "CAN"T FIND HANDLER ERROR==============
put the result into theError
if theError is empty then
set the dgData of group "DataGrid 1" to theDataGridArray
#put the dgIndexes of group "DataGrid 1" into theIndexes
put the dgNumberOfLines of group "DataGrid 1" into Totalrows --tong so dong co trong datagrid
#answer Totalrows
end if
## Close the database cursor
revCloseCursor theCursor
end if
## Close the database connection
revCloseDatabase gConnectionID
else
answer "Error connecting to the database:" && gConnectionID & "."
end if
end mouseUp
I'm so appreciated for your help
Quang