Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Use the GUI class within another class
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ItsMe




PostPosted: Mon Jan 11, 2010 12:17 am   Post subject: Use the GUI class within another class

What is it you are trying to achieve?
I'm trying to use a GUI class within another class.


What is the problem you are having?
It can't compile and the status bar shows "Class subprograms cannot be subprogram variables".


Describe what you have tried to solve this problem
A workaround, I found, was to use module instead of class. Ignoring this, is there any other possible ways?


Test.tu

Turing:

unit
class Test
    import GUI
    export initialize
   
    var variable, button : int := 0

    proc print
        put variable
    end print

    proc initialize
        button := GUI.CreateButton (50, 50, 100, "Assign", print)
    end initialize
end Test


Test.t
Turing:

import Test, GUI

var test : ^Test
new Test, test

Test (test).initialize

loop
    exit when GUI.ProcessEvent
end loop


Please specify what version of Turing you are using
4.1.1 and 4.1

Thanks,
A noob who tries to learn OOP
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: Mon Jan 11, 2010 5:15 pm   Post subject: RE:Use the GUI class within another class

I don't think this is possible, because the integer that GUI.CreateButton returns is just a number to identify the button, so if the object gets destroyed, the button still exists. Therefore if the function the button activates was part of the object and would now be deleted, the button which still exists would no longer have a function to call.

In other words, you are hitting the limitations of Turing (or at least its GUI module)

Hope that helps.
DemonWasp




PostPosted: Mon Jan 11, 2010 10:24 pm   Post subject: RE:Use the GUI class within another class

You may want to try passing self.print into GUI.CreateButton. No guarantees, but it seems more likely to work as that's a proper method invocation, which is what GUI.CreateButton is expecting. You can't call print(), but you can call <instance-of-Test>->print() .
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: