Exemple #1
0
        void form_load(Object _sender, EventArgs _e1)
        {
            try
            {
                _macroDefinition.SetParser(m_parser);

                // Define the variables and keep the keys to speed up value assignations
                m_parser.defineVar(m_x as IMTVariable);
                m_parser.defineVar(m_y as IMTVariable);
                m_parser.defineVar(m_z as IMTVariable);

                // Define a shared double variable for test purpose
                MTDouble v = new MTDouble();

                v.create("v", 1.0);
                m_parser.defineVar(v as IMTVariable);
                double r = 0;

                r = m_parser.evaluate("v");

                // Change the variable's value
                v.value = 10.0;

                r = m_parser.evaluate("v");
                Console.Out.WriteLine("r = {0}", r);

                // Create another parser and copy the existing parser configuration
                MTParser p2 = new MTParser();
                p2.copy(m_parser);

                r = p2.evaluate("v");

                // the shared variable has been copied
                // Changing the shared variable's value updates all parsers using this variable
                v.value = 3.0;
                r       = p2.evaluate("v");
                r       = m_parser.evaluate("v");

                // define a constant
                m_parser.defineConst("pi", 3.14159);

                // define  a user-defined function
                m_parser.defineFunc(new MySumFunction());

                // Load localized information
                string            dir       = System.AppDomain.CurrentDomain.BaseDirectory;
                MTParserLocalizer localizer = new MTParserLocalizer();
                localizer.locale = "en";
                localizer.registerAllLibraries(dir, "*.xml");


                sMTSyntax syntax = m_parser.getSyntax();
                syntax.decimalPoint      = '.';
                syntax.argumentSeparator = ',';
                m_parser.setSyntax(ref syntax);

                // Load plug-ins
                m_parser.loadAllPlugins(dir, "*.xml");
            }
            catch (Exception)
            {
                MessageBox.Show("Error: " + getLastExcepText(m_parser), "Project1");
            }
        }
		void form_load(Object _sender, EventArgs _e1) 
		{			
			try
			{				
				_macroDefinition.SetParser( m_parser ) ;

				// Define the variables and keep the keys to speed up value assignations
				m_parser.defineVar(m_x as IMTVariable);
				m_parser.defineVar(m_y as IMTVariable);
				m_parser.defineVar(m_z as IMTVariable);
				
				// Define a shared double variable for test purpose
				MTDouble v = new MTDouble();				

				v.create("v", 1.0);
				m_parser.defineVar(v as IMTVariable);
				double r = 0;
								
				r = m_parser.evaluate("v");
				
				// Change the variable's value
				v.value = 10.0;				

				r = m_parser.evaluate("v");
				Console.Out.WriteLine( "r = {0}", r ) ;

				// Create another parser and copy the existing parser configuration
				MTParser p2 = new MTParser();
				p2.copy(m_parser);

				r = p2.evaluate("v");				

				// the shared variable has been copied
				// Changing the shared variable's value updates all parsers using this variable
				v.value = 3.0;
				r = p2.evaluate("v");
				r = m_parser.evaluate("v");

				// define a constant
				m_parser.defineConst("pi", 3.14159);

                // define  a user-defined function
                m_parser.defineFunc(new MySumFunction());
				
				// Load localized information
				string dir = System.AppDomain.CurrentDomain.BaseDirectory;				
				MTParserLocalizer localizer = new MTParserLocalizer();
				localizer.locale = "en";				
				localizer.registerAllLibraries( dir, "*.xml");								
				

				sMTSyntax syntax = m_parser.getSyntax();				
				syntax.decimalPoint = '.';
				syntax.argumentSeparator = ',';
				m_parser.setSyntax(ref syntax);
				
				// Load plug-ins				
				m_parser.loadAllPlugins( dir, "*.xml");

              
                
				
				
			}
			catch ( Exception )
			{
				MessageBox.Show("Error: " + getLastExcepText(m_parser), "Project1");
			}
		}