Results 1 to 1 of 1

Thread: CODEPTR new feature in thinBasic 1.10.5

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,817
    Rep Power
    10

    CODEPTR new feature in thinBasic 1.10.5

    thinBasic 1.10.5 introduces CODEPTR, a new feature usually not available in interpreted languages that do not have scripts compiled in binary code.

    https://www.thinbasic.com/public/pro...ml?codeptr.htm

    CODEPTR is the equivalent of a pointer to a sub/function or in general a pointer to an execution memory address.
    It is used to pass to external library a pointer to a function in such a way external library can invoke back the function.
    For example Windows SDK programming uses it for events callbacks.

    In thinBasic you can use CODEPTR in many ways, let's see some examples.

    Subclassing a control (textbox, button, ...)
    "If a control does almost everything you want, but you need a few more features, you can change or add features to the original control by subclassing it.
    A subclass can have all the features of an existing class as well as any additional features you want to give it."
    More info at https://docs.microsoft.com/en-us/win...ssing-overview

    You can get an example in \thinBasic\SampleScripts\UI\SDK\TextBox_SubClass.tbasic script.
    In that example we have a textbox that does ALMOST what we need because we want also: no space allowed in the textbox, not possible to paste text using copy/paste.

    Subclassing means: substitute standard events function of the control with your own one in order to receive events before the standard events function.
    You can decide which events to handle and which events pass to original events function

    Allows external library call your script functions when needed
    There are some libraries that needs to talk back to the caller in order to signal that something has happened and a decision on what to do must be taken.
    This is topical of User Interface libraries when an event is fired but the decision of what to do is not to be taken by the library but by the caller.

    Have a look at IUP library: http://iup.sourceforge.net/
    IUP is a User Interface library that implement a simple way to develop Windows with controls and interact with them

    In thinBasic see example \thinBasic\SampleScripts\IUP\_IUP_NotePad.tbasic
    A simple (not yet finished) example of a simple Notepad like window.
    At some point, for every command, you need to decide what to do. To do so you need to tell IUP what script function to call for a certain control.
    In IUP you call IupSetCallback function telling what control you want to handle events, and which script function call when an event occurs:
    IupSetCallback(item_exit, "ACTION", CodePtr(exit_cb))
    

    Write pure Windows SDK programming
    This is quite complex at first but when mastered ... you can do what you want the way you want in Windows.
    A thinBasic example showing how to create a Window in SDK programming can be found at: \thinBasic\SampleScripts\UI\SDK\WinApp_SDK.tbasic
    It is very basic but only using Windows API:

    1. creates a pure SDK window
    2. add a menu
    3. react to some events showing into a console some data


    You can make a copy of this script and add more functionalities.

    Please read thinBasic CODEPTR help at https://www.thinbasic.com/public/pro...ml?codeptr.htm
    reading how such functionality has been developed and what are the current limitations.

    Hope you like it.
    Last edited by ErosOlmi; 17-10-2018 at 21:38.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. thinBasic 1.10.5 help on testing a new feature
    By ErosOlmi in forum thinBasic Beta testing
    Replies: 11
    Last Post: 30-11-2017, 00:00
  2. New forum feature: calendar
    By ErosOlmi in forum Web and Forum
    Replies: 2
    Last Post: 17-07-2008, 11:25

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •