Page 1 of 1
How to call a function in another object?
Posted: Sun Nov 29, 2009 6:36 pm
by ale870
Hello,
I have two questions (two problems!).
1) I created a function in a button, but I want to recall that function from another button. I cannot write something like: get myFunc(val1, val2) of button "anotherButton" since it does not work. How can I do that?
2) SImilar question but for custom commands. I can write: myMessage val1, val2 and to call it in another object I can use: send "myMessage val1, val2" of stack "anotherStack". Well, how can I do that using the first syntax? myMessage val1, val2 of stack "anotherStack"
Thank you for your help!
Re: How to call a function in another object?
Posted: Sun Nov 29, 2009 8:05 pm
by mwieder
#1A: Unless you really have a need for the "myFunc" function to live in the "anotherButton" button, why not place the function in the card script? Or barring that, use a behavior button script and set the behavior of both buttons to the long id of the behavior button - that way just those two buttons will inherit the "myFunc" function.
#1B: Check out the "value" command.
#2: Check out the "value" command
Re: How to call a function in another object?
Posted: Sun Nov 29, 2009 9:49 pm
by ale870
Thank you.
I solved the problems (a few minutes ago!) using the command "start using" and "insert script".
Thank you!
Re: How to call a function in another object?
Posted: Thu Mar 31, 2011 8:41 am
by QuangNgo
Hi guys ,
I have just been the beginer of working with Live code . There has been problem with my code ,but don't know to fix it .
Here is my code:
on mouseUp
#call method ConnectionDD to establish connection
call ConnectionDD of card "Dbconnection" of stack "DataLayoutAccess"
#call method getExecuteSelect to retrieve database by storeprocedure
#put value to parameters
#put "selectstudents()" into lprocedurename
call getExecuteSelect ("selectstudents()") into lTemp //problem here It doesn't go to function getexecute //
if item 1 of LTemp = "revdberr" then
answer error "There was a problem querying the database:" & cr & tData
else
put LTemp into field "TData"
end if
end mouseUp
Hope you could fix that problem for me.
Thank so much
Quang
Re: How to call a function in another object?
Posted: Fri Apr 01, 2011 3:32 am
by mwieder
call getExecuteSelect ("selectstudents()") into lTemp //problem here It doesn't go to function getexecute //
Well, that's not the right syntax for the call statement. Actually there are very few times when I use call statements. They're very specialized things and I think of them as ways to get around the normal messaging hierarchy when there isn't any other way around it. What I would do instead is place the handlers where they would be accessed without having to resort to such tricks.
I don't know where you've place the getExecuteSelect() and selectstudents() functions, but my guess from your code snippet is that it's in the same object as the script you posted. In that case the syntax would be
Code: Select all
put getExecuteSelect (selectstudents()) into lTemp
See Richard Gaskin's writeup on the message path
http://www.fourthworld.com/embassy/arti ... _path.html for more details.
Re: How to call a function in another object?
Posted: Fri Apr 01, 2011 5:39 am
by QuangNgo
Thank a lot
I fixed that problem .
Quang
Re: How to call a function in another object?
Posted: Mon Apr 04, 2011 11:15 am
by QuangNgo
Hi guy sorry to bother again
I know that issue might be easy for you ,but I try and don't know why it doesn't work?
Here is my code:
global gConnectionID
on mouseUp
--Call
#call OpenConnection of card "DBConnection" of stack "InventoryDataAccessLayer"
put "localhost" into lDatabaseAddress
put "quangtemp" into lDatabaseName
put "root" into lDatabaseUser
put "1234567" into lDatabasePassword
-- connect to the database
put revdb_connect("MySQL", lDatabaseAddress, lDatabaseName, lDatabaseUser, lDatabasePassword) into tResult
-- check if it worked and display an error message if it didn't
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
-- set this to the name of a table in your database
put "call test1()" into tSQL
-- query the database
put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
-- check the result and display the data or an error message
if item 1 of tData = "revdberr" then
answer error "There was a problem querying the database:" & cr & tData
else
put tData into lArray
=========the problem here it doesn't get value from lArray ,sorry I try to read many source but It doesn't help
# put "Hi" into theA[1]["Name"]
#put "23" into theA[1]["Age"]
set the dgData of group "DataGrid" to theA
call closeConnection
end if
end mouseUp
on closeConnection
-- 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
I'm so appreciated for your help
Quang