Can't find handler error Problem

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

Can't find handler error Problem

Post by QuangNgo » Fri Apr 08, 2011 6:54 am

Hi guys,

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

SparkOut
Posts: 2946
Joined: Sun Sep 23, 2007 4:58 pm

Re: Can't find handler error Problem

Post by SparkOut » Fri Apr 08, 2011 4:48 pm

You almost certainly don't need to "call" the command, once a handler is defined as a command, it is invoked whenever you use its name. I have never seen a livecode script "in the wild" that actually uses a "call" statement.
I haven't got a test situation to see if there is any more issue with your code, but I believe the reason you get the handler not found error is that when you invoke the command from the application stack (mainstack) it is already higher in the message path than the substack which contains the handler.
To make a library out of a substack, in the mainstack you can:

Code: Select all

start using "MyLibrary"
which will include the substack and its scripts in the message path hierarchy, and hence be available to all the objects and scripts in the project. It can be handy to do this in an openStack handler of the mainstack, for instance. When cleaning up, you can stop using "substack" as necessary, or close the whole application gracefully as you need.

QuangNgo
Posts: 60
Joined: Thu Mar 31, 2011 8:31 am

Re: Can't find handler error Problem

Post by QuangNgo » Sun Apr 10, 2011 10:27 am

Thank you so much SparkOut,
I'm doing with your help , so sorry because of posting my script fourth threads.
Anyway thank for your help.
Quang :D

Post Reply