Use the GUI class within another class 
	 
	
		| Author | 
		Message | 
	 
		 
		ItsMe
 
 
 
    
		 | 
		
		
			
				  Posted: 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 
		 
  
		 | 
		
 | 
	 
	 
		  | 
	 
				 
		TerranceN
 
 
 
    
		 | 
		
		
			
				  Posted: 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
 
 
 
    
		 | 
		
		
			
				  Posted: 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() . | 
			 
			
				 | 
			 
		  | 
	 
	 
		 | 
		
		 | 
	 
	  
		  | 
	 
				 
		 | 
	 
 
	
	
	 
	
	 |