We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ZS Extension.
#61
Hi,
I do output the reported exception message, they don't usually say how to fix. Sometimes Google of the message can give clues.  Otherwise, simplify with a small test extension.
If you share your extension I can maybe see something.
Reply
#62
Today I have a question.
While I was making Raylib I thought about something.
In Raylib all 2d position are in vector2 and 3d in vector3.
All was going till now good I use like this in method X-Y for vector2 whenever needed but we have another option.
I could also make method for creating vector2 and then we could use them directly and in this way it would be more easier to change value of vectors as Raylib work on a main while loop which got executed for every frame.
I can implement both options but I wanted to know which is easier for users.
ZS
Reply
#63
I think you should decide yourself and then provide examples  Smile
[-] The following 1 user Likes litdev's post:
  • z-s
Reply
#64
I found the reflection stuff in csharp very amazing I completely replaced the old zsplatform class with zsreflection.
Adding function for field and method invoking.
In that search I found something amazing in my extension the graphics window was taken as a wpf window class from its handle which was get by the title of window same thing we could test with small basic editor as a addin for much powerful graphics.
But I fears may playing with reflection is dangerous can cause the application unresponding be aware.
And I found a new thing the 2d and 3d rendering through ld3dview is done in WPF by direct3d 9
ZS
[-] The following 1 user Likes z-s's post:
  • litdev
Reply
#65
Litdev could you explain me about creating and using small basic events with deglate.
Routed event handler???
ZS
Reply
#66
Hi,

A varaible that holds a function is called a delegate.  The delegate function can be passed as an argument and then called for example.

So if we take LDControls.MenuClicked as an example, there are several bits:

1] An event from the OS or some .Net object, in this case, when a menu item is clicked

Code:
menuItem.Click += new RoutedEventHandler(_MenuClickEvent);

This says that when a menu item is clicked the delegate function _MenuClickEvent will be called, this is a private static function, it will pass the object that raised the event and some event arguments (often specific to the event).

2] The event handler delegate function.

Code:
        private static void _MenuClickEvent(Object sender, RoutedEventArgs e)
        {
            MenuItem _item = (MenuItem)sender;
            _LastMenuContol = (string)_item.Tag;
            _LastMenuItem = (string)_item.Header;
            e.Handled = true;
            if (null == _MenuClickDelegate) return;
            _MenuClickDelegate();
        }

In this handler we can get the calling object from sender (in this case a menu), and we can set some parameters that can be passed back to the user about the event as properties, like which menu iten was clicked, and finally we call another delegate function (_MenuClickDelegate, if it has been set) which will call the User's event subroutine.

The e.Handled = true says that the mouse click event does not need to be passed (re-routed) to other events, this is not usually needed for most events.

3] We have to set up the user function (_MenuClickDelegate) to call.  Initially this is a null delegate:

Code:
private static SBCallback _MenuClickDelegate = null;

Where I define SBCallBack with a using.  This is not necessary, you can just use SmallBasicCallback, but I do it this way so I can easily switch between SB and sVB:

Code:
using SBCallback = Microsoft.SmallBasic.Library.SmallBasicCallback;

4] Finally, if the user wants this event then they set it using an event command:

Code:
        /// <summary>
        /// Event when a menu item is selected.
        /// </summary>
        public static event SBCallback MenuClicked
        {
            add
            {
                _MenuClickDelegate = value;
            }
            remove
            {
                _MenuClickDelegate = null;
            }
        }

So when the user clicks a menu item, the delegate _MenuClickEvent is called, and if the user has subsribed to this event, then their Small Basic event subroutine _MenuClickDelegate (set by LDControls.MenuClicked = OnMenuClicked, where OnMenuClicked is their SB event subroutine, asigned to _MenuClickDelegate) is called and they can also get info about the event that was set in _MenuClickEvent like which menu control and item was clicked.
[-] The following 1 user Likes litdev's post:
  • z-s
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)