[Newbie!] Pointers and Multi-Windows

Mac OSX specific forum
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

[Newbie!] Pointers and Multi-Windows

Post by syntonica »

I've been kicking tires on PB for a few days now. I have a mature Java application I wish to port to get away from Java, but still be easily cross-platform. So far, I'm quite impressed how the PB IDE runs with the snappy in under 100MB while my ultra-stripped Eclipse chews up 650MB and never gives it back.

Me: int i = 0;
Java: Whoa there, buddy! That's an awfully big ask on memory. Hey, boys! We got a half-GB to spare?

Anyway, my app is multi-windowed and each window is a state-machine with every little thing stores as a key/value pair in a db unique to that instance. So,before I hit my 800 line limit and have to decide if I can get my credit card out of the safe, I have a weird problem to solve.

Firstly, I'm running an 11" MacBook Potato running all that Monterey has to offer. I'm using the latest version of PB, as well. The following code is very stripped down. I'm just looking at the Pointer syntax and operation, nothing else.

Code: Select all

	Structure AV
		*AVWindow
		*StatusBar
	EndStructure
	
	Procedure AVOpenWindow(*ThisAV.AV, Title.s, x = 0, y = 0, width = 800, height = 600)
		*ThisAV\AVWindow = OpenWindow(#PB_Any, x, y, width, height, Title)
	
		*ThisAV\StatusBar = CreateStatusBar(#PB_Any, *ThisAV\AVWindow)  ; This crashes here with "Invalid memory access"
		AddStatusBarField(220)
However, this works fine.

Code: Select all

		OpenWindow(0, x, y, width, height, Title,)
	
		 CreateStatusBar(0, *ThisAV\AVWindow)  ; :D
		AddStatusBarField(220)
I have to say, Pointers are quite strange on PB, so please tell me where I've gone astray. I've inspected all my pointers and they appear to be valid (can't see into a Structure in the debugger, can I?). They are al in the same MB range, so are breing allocated.

Where am I going wrong here?
Thanks.
User avatar
idle
Always Here
Always Here
Posts: 6197
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: [Newbie!] Pointers and Multi-Windows

Post by idle »

you want something like this

Code: Select all

Structure AV
  AVWindow
  StatusBar
EndStructure

Procedure AVOpenWindow(*ThisAV.AV, Title.s, x = 0, y = 0, width = 800, height = 600)
  *ThisAV\AVWindow = OpenWindow(#PB_Any, x, y, width, height, Title)
  
  *ThisAV\StatusBar = CreateStatusBar(#PB_Any, *ThisAV\AVWindow)  ; This crashes here with "Invalid memory access"
  AddStatusBarField(220)
  
EndProcedure 		

Global gav.AV 

AVOpenWindow(@gav, Title.s, 0, 0);

User avatar
spikey
Addict
Addict
Posts: 806
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: [Newbie!] Pointers and Multi-Windows

Post by spikey »

Hello and Welcome syntonica!

PureBasic maintains its own gadget numbers which are separate from the OS's Window ID or handle. Some commands require a number, others an ID or handle. You're supplying a number to a command which wants an ID, in this case CreateStatusBar requires a WindowID not a window number.

Have a read of these which should make things clearer:
PureBasic objects
Handles

You don't need to be so complicated however. Your structure doesn't need to contain pointers - and I would argue shouldn't because you aren't storing true pointers but PB numbers. Integers would be fine.

You also don't necessarily need to pass in pointers to structured variables either (a structured variable is a pointer). You can supply a structured variable as an argument directly. (I think this applies to MacOS too, somebody will be certain to correct me if I'm wrong!)

Code: Select all

Structure AV
  AVWindow.I
  StatusBar.I
EndStructure

Procedure AVOpenWindow(*ThisAV.AV, Title.s, x = 0, y = 0, width = 800, height = 600)
  *ThisAV\AVWindow = OpenWindow(#PB_Any, x, y, width, height, Title)
  
  *ThisAV\StatusBar = CreateStatusBar(#PB_Any, WindowID(*ThisAV\AVWindow))
  AddStatusBarField(220)
  StatusBarText(*ThisAV\StatusBar, 0, "Hello, World!")
  
EndProcedure 		

Global gav.AV 

AVOpenWindow(gav, Title.s, 0, 0);

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

Re: [Newbie!] Pointers and Multi-Windows

Post by syntonica »

By Jove, I think I got it! My GUI is now up and running and resizing without blowups. I'm so used to explicit pointers when passing structures, it had me tangled up. Thanks to the both of you!

Question: Does #PB_Any generate large Integers? If so, that may be part of my confusion. I thought I read GadgetNumbers were 16-bit in size.

Unfortunately, the manual confuses me more than it helps. PB is very Pascally-wascally in its way and I'm having a problem shifting gears. I'm used to Java, which is very sloppy with lifetimes and such, with no pointers, and C/C++, in which I can be extremely explicit with memory/object usage.

Regarding MacOs, the IDs are basically void pointers with a nicer name. It is Objectivre-C : C under the hood with a simple class system glued on. It's pointers al the way down.

Anyway, I have another 185 lines left to see if I can add a menu bar to the window and bypass the macOS menu bar altogether, like Java. I have one menu that is built on the fly when the window opens.
User avatar
mk-soft
Always Here
Always Here
Posts: 6579
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Newbie!] Pointers and Multi-Windows

Post by mk-soft »

Welcome!

In PureBasic, you can specify Windows, gadgets, etc. as IDs (PB-Object IDs) or as #PB_Any.
If you specify an ID (starting with zero), PB manages the Windows and gadgets internally as an array (which is very fast).
If you specify #PB_Any as the ID, the PB object is created dynamically. This must be stored as an integer. You must be release with CloseWindow, FreeGadget, etc to avoid memory leak.
Each object type has its own area as an array or dynamic memory.

I prefer to use constants myself. Unless I want to open a window several times. Then I also use #PB_Any and a structure.

To test codes, I have created a template so that I can quickly open a window.
Also to show how event management works in PureBasic for beginners.

Template

Code: Select all

;-TOP

#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"

Enumeration Windows
  #Main
EndEnumeration

Enumeration MenuBar
  #MainMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuAbout
  #MainMenuExit
EndEnumeration

Enumeration Gadgets
  #MainEdit
  #MainButtonOk
  #MainButtonCancel
EndEnumeration

Enumeration StatusBar
  #MainStatusBar
EndEnumeration

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
  ; Resize gadgets
  ResizeGadget(#MainEdit, 5, 5, dx - 10, dy - 45)
  ResizeGadget(#MainButtonok, 10, dy - 35, 120, 30)
  ResizeGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30)
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("&File")
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      MenuItem(#PB_Menu_About, "")
    CompilerElse
      MenuItem(#MainMenuAbout, "About")
    CompilerEndIf
    ; Menu File Items
    
    CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
      MenuBar()
      MenuItem(#MainMenuExit, "E&xit")
    CompilerEndIf
    
    ; StatusBar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    EditorGadget(#MainEdit, 5, 5, dx -10, dy - 45)
    ButtonGadget(#MainButtonok, 10, dy - 35, 120, 30, "Ok")
    ButtonGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30, "Abbruch")
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    ; Event Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              Break
              
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
            CompilerEndIf
            
          Case #MainMenuAbout
            MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
              
          Case #MainMenuExit
            PostEvent(#PB_Event_CloseWindow, #Main, #Null)
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #MainEdit
              Select EventType()
                Case #PB_EventType_Change
                  ;
                  
              EndSelect
              
            Case #MainButtonOk
              ;
            Case #MainButtonCancel
              ;
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

Re: [Newbie!] Pointers and Multi-Windows

Post by syntonica »

Thanks, mk! I can always use templates.

I got my per-window pseudo-menubar up and running. One last question is:

How do I disable that pesky right-click Context Menu that Apple has so graciously supplied and replae it with my own? Will I have to go spielunking in Cocoa? Or, is there a quick one-liner to opt out?
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

Re: [Newbie!] Pointers and Multi-Windows

Post by syntonica »

Doh! Never mind! I found the answer on the forum. First time from all mt searches.

Unfortunately, it has to be done percomponent... :(
User avatar
mk-soft
Always Here
Always Here
Posts: 6579
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Newbie!] Pointers and Multi-Windows

Post by mk-soft »

PureBasic provides the largest common denominator of functions for Windows, Linux, macOS.

For OS-specific customization, PureBasic in the full version prepares access to (almost) all API functions of the respective OS.
With Windows, WindowID, etc. the handle is returned, with macOS and linux to the object.
So you can adjust or change everything yourself.
The easiest way to get rid of the context menu is to set the menu to NIL in NSTextView or to set your own menu.

Update to full code

Code: Select all

;-TOP Dump Object Methods

; by mk-soft, 29.12.2019 - 07.02.2026, v1.09.3

Declare.s DumpObjectMethods(*Object, SuperLevel = 0, HidePrivate = #True, ShowEncoding = #False, FirstArgument = 2)

Structure ArrayOfMethods
  i.i[0]
EndStructure

ImportC ""
  class_copyMethodList(*Class, *p_methodCount)
  ; -> An array of pointers of type Method describing
  ;    the instance methods implemented by the class
  ;    Any instance methods implemented by superclasses are Not included
  ;    You must free the array with free()
  class_getName(*Class) ; -> UnsafePointer<Int8> -> *string
  sel_getName(*Selector); -> const char *
  method_getName(*Method) ; -> Selector
  method_getTypeEncoding(*Method) ; -> const char *
  method_getReturnType(*Method, *dst, dst_len) ; -> void
  method_getNumberOfArguments(*Method)         ; -> unsigned int
  method_getArgumentType(*Method, index, *dst, dst_len) ; -> void
  
  NSGetSizeAndAlignment(*StringPtr, *p_size, *p_align) 
  ; -> const char *
  ;    Obtains the actual size and the aligned size of an encoded type.
EndImport

; ----

Procedure.s GetArgumentType(*String)
  Protected r1.s, arg.s, size.i, ofs.i
  
  arg = PeekS(*String, -1, #PB_UTF8)
  r1 + arg + " - "
  If Left(arg, 1) = ""
    r1 + "A pointer to type of "
    arg = Mid(arg, 2)
  EndIf
  Select arg
    Case "c" : r1 + "A char "
    Case "i" : r1 + "An int "
    Case "s" : r1 + "A short "
    Case "l" : r1 + "A long "
    Case "q" : r1 + "A long long"
    Case "C" : r1 + "An unsigned char "
    Case "I" : r1 + "An unsigned int "
    Case "S" : r1 + "An unsigned short "
    Case "L" : r1 + "An unsigned long "
    Case "Q" : r1 + "An unsigned long long "
    Case "f" : r1 + "A float "
    Case "d" : r1 + "A double "
    Case "B" : r1 + "A C++ bool Or a C99 _Bool "
    Case "v" : r1 + "A void"
    Case "*" : r1 + "A character string (char *) "
    Case "@" : r1 + "An object (whether statically typed Or typed id) "
    Case "#" : r1 + "A class object (Class) "
    Case ":" : r1 + "A method selector (SEL) "
    Default:
      If FindString(arg, "CGLContext")
        ; Ignore
      ElseIf FindString(arg, "CAContext")
        ; Ignore
      Else
        NSGetSizeAndAlignment(*String, @size, @ofs)
        r1 + "[" + Str(size) + " bytes]"
      EndIf
  EndSelect
  If Right(arg, 1) = "?"
    r1 + "An unknown type (e.g. function pointer)"
  EndIf
  ProcedureReturn r1
EndProcedure

; ----

Procedure.s DumpObjectMethods(*Object, SuperLevel = 0, HidePrivate = #True, ShowEncoding = #False, FirstArgument = 2)
  Protected result.s, r1.s, i, c, n, methodCount, Method.s
  Protected *Class, *SuperClass, *Method, *Methods.ArrayOfMethods
  Protected *String
  
  *Class = object_getclass_(*Object)
  If *Class
    *String = AllocateMemory(1024)
    r1 = PeekS(class_getName(*Class), -1, #PB_UTF8)
    If SuperLevel
      For i = 1 To SuperLevel
        *SuperClass = class_getsuperclass_(*Class)
        If *SuperClass
          *Class = *SuperClass
          r1 + " -> " + PeekS(class_getName(*Class), -1, #PB_UTF8)
        Else
          Break
        EndIf
      Next
    EndIf
    *Methods = class_copyMethodList(*Class, @methodCount)
    r1 + #LF$ + #LF$ + "Count of Methods: " + methodCount + #LF$
    result = r1 + #LF$
    Debug r1
    r1 = ""
    For i = 0 To methodCount - 1
      *Method = *Methods\i[i];
      Method = PeekS(sel_getName(method_getName(*Method)), -1, #PB_UTF8)
      If HidePrivate And Left(Method, 1) = "_"
        Continue
      EndIf
      r1 + "Method " + Method + #LF$
      If ShowEncoding
        r1 + " * Encoding " + PeekS(method_getTypeEncoding(*Method), -1, #PB_UTF8) + #LF$
      EndIf
      method_getReturnType(*Method, *String, 1024)
      r1 + " -- ReturnType = " + GetArgumentType(*String) + #LF$
      c = method_getNumberOfArguments(*Method)
      For n = FirstArgument To c - 1
        method_getArgumentType(*Method, n, *String, 1024)
        r1 + " -- Argument " + Str(n - FirstArgument + 1) + " = " + GetArgumentType(*String) + #LF$
      Next
      result + r1 + #LF$
      Debug r1
      r1 = ""
    Next
    r1 + "End Class" + #LF$
    result + r1 + #LF$
    Debug r1
    If *Methods
      free_(*Methods)
    EndIf
    FreeMemory(*String)
  Else
    r1 = "Object is nil" + #LF$
    result = r1
    Debug r1
  EndIf
  ProcedureReturn result
EndProcedure

; ****


;-TOP

#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"

Enumeration Windows
  #Main
EndEnumeration

Enumeration MenuBar
  #MainMenu
  #EditMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuAbout
  #MainMenuExit
  #EditMenuCopy
  #EditMenuPaste
EndEnumeration

Enumeration Gadgets
  #MainEdit
  #MainButtonOk
  #MainButtonCancel
EndEnumeration

Enumeration StatusBar
  #MainStatusBar
EndEnumeration

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
  ; Resize gadgets
  ResizeGadget(#MainEdit, 5, 5, dx - 10, dy - 45)
  ResizeGadget(#MainButtonok, 10, dy - 35, 120, 30)
  ResizeGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30)
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("&File")
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      MenuItem(#PB_Menu_About, "")
    CompilerElse
      MenuItem(#MainMenuAbout, "About")
    CompilerEndIf
    ; Menu File Items
    
    CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
      MenuBar()
      MenuItem(#MainMenuExit, "E&xit")
    CompilerEndIf
    
    ; StatusBar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    EditorGadget(#MainEdit, 5, 5, dx -10, dy - 45)
    ButtonGadget(#MainButtonok, 10, dy - 35, 120, 30, "Ok")
    ButtonGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30, "Abbruch")
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    ; Editor Context Menu
    CreatePopupMenu(#EditMenu)
    MenuItem(#EditMenuCopy, "Copy")
    MenuItem(#EditMenuPaste, "Paste")
    
    obj = GadgetID(#MainEdit)
    DumpObjectMethods(obj, 0)
    DumpObjectMethods(obj, 1)
    
    menu = CocoaMessage(0, obj, "menu")
    ;DumpObjectMethods(menu, 0)
    
    CocoaMessage(0, obj, "setMenu:", MenuID(1))
    
    ; Event Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              Break
              
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
            CompilerEndIf
            
          Case #MainMenuAbout
            MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
              
          Case #MainMenuExit
            PostEvent(#PB_Event_CloseWindow, #Main, #Null)
            
          Case #EditMenuCopy
            Debug "Copy of Gadget " + GetActiveGadget()
            
          Case #EditMenuPaste
            Debug "Paste of Gadget " + GetActiveGadget()
            SetGadgetText(#MainEdit, GetClipboardText())
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #MainEdit
              Select EventType()
                Case #PB_EventType_Change
                  ;
                  
              EndSelect
              
            Case #MainButtonOk
              ;
            Case #MainButtonCancel
              ;
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()
Link to DumpObjectMethods: viewtopic.php?t=74278
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

Re: [Newbie!] Pointers and Multi-Windows

Post by syntonica »

Hi All,

It's looking like, sadly, PB is probaby not going to be able to do it for me without extensive platform-specific customization. That thing I wish to avoid.

What I need that I'm not seeing:

-Fine-graied access to an Editor widget, i.e. arbitrary access to the text in thebacking store, the ability to veto keysrokes, or sanitize any text before inserting and capturing that change. The EditorGadget is far too light-weight and the ScintillaGadget is the 800-pound gorilla of WTF? I need something in-between, if it exists. If not, I can grit my teeth and learn Scitilla, but their docs are NOT helping...
-The ability to capture/bind keystrokes to/from any widget.
-My application uses a custom Undo/Redo system that captures all changes to the program state, including three text areas, q.v. my previous point.
-Buttons need to be focusable to take keyboard input. It's a QOL-thing to make the GUI as fully kryboard driven as possible. I might even add a VIM-mode one day.
-There's some cosmetic issues that need to be dealt with at the OS level.

I can get around a lot of this with different design choices. Unfortunately, my design paradigms are always at odds with Apple/MS/Linux paradigms.

I'm loving the memory footprint of this this thing. The release executable is under a 1MB right now and if embed the resource files, it would only be ~10MB in size. I loaded my largest project (1.2MB. Thanks, XML!) and the release version sits at ~25MB memoru consumtion. The Java version uses over ~150MB and can go up to ~600MB! And it will never return the memory. The speed/responsiveness is excellent, actaully better. Java is speed-optimized, but at the expense of more and more RAM.
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

Re: [Newbie!] Pointers and Multi-Windows

Post by syntonica »

mk-soft wrote: Sat Feb 07, 2026 11:54 am PureBasic provides the largest common denominator of functions for Windows, Linux, macOS.

For OS-specific customization, PureBasic in the full version prepares access to (almost) all API functions of the respective OS.
With Windows, WindowID, etc. the handle is returned, with macOS and linux to the object.
So you can adjust or change everything yourself.
The easiest way to get rid of the context menu is to set the menu to NIL in NSTextView or to set your own menu.

Update to full code

Code: Select all

...
    ButtonGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30, "Abbruch")
 ...
Link to DumpObjectMethods: viewtopic.php?t=74278
Tha's what I love about German. You don't Cancel, you Break Up. :)

Thanks for the code. I have to say, it's very neatly organized and I can read it easily. I'm still struggling with this in free-form BASIC where anything can go anywhere...
User avatar
spikey
Addict
Addict
Posts: 806
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: [Newbie!] Pointers and Multi-Windows

Post by spikey »

syntonica wrote: Sat Feb 07, 2026 6:53 pm without extensive platform-specific customization. That thing I wish to avoid.
I'm not aware of any language that can do this without the implementation of an abstraction layer of some description - but with that will come with at least some of the downsides of what you are seeing in Java, for the same reasons.
syntonica wrote: Sat Feb 07, 2026 6:53 pm -Fine-graied access to an Editor widget, i.e. arbitrary access to the text in thebacking store, the ability to veto keysrokes, or sanitize any text before inserting and capturing that change. The EditorGadget is far too light-weight and the ScintillaGadget is the 800-pound gorilla of WTF? I need something in-between, if it exists. If not, I can grit my teeth and learn Scitilla, but their docs are NOT helping...
Scintilla is the way to go here.
syntonica wrote: Sat Feb 07, 2026 6:53 pm -My application uses a custom Undo/Redo system that captures all changes to the program state, including three text areas, q.v. my previous point.
Nothing here that can't be achieved in PureBasic. Not in 800 lines though.
syntonica wrote: Sat Feb 07, 2026 6:53 pm -Buttons need to be focusable to take keyboard input. It's a QOL-thing to make the GUI as fully kryboard driven as possible. I might even add a VIM-mode one day.
See AddKeyboardShortcut. (Although I'm not entirely certain that I'm thinking the same thing that you are here).

You could look at something like Embarcadero Delphi which is an OOP langauge and might be less of a culture shock for you. But if you're worried about the price of PureBasic, the price of Delphi will probably be a shock!
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

Re: [Newbie!] Pointers and Multi-Windows

Post by syntonica »

spikey wrote: Sat Feb 07, 2026 8:38 pm I'm not aware of any language that can do this without the implementation of an abstraction layer of some description - but with that will come with the downsides of what you are seeing in Java, for the same reasons.
That's the one thing Java does do: it's very platform independent. On MacOS, I only need 3 or 4 properties to set to disable Mac's pervading and annoying helpfulness. MacOS native widgets are ugly and frustratingly bad unless one follows their design slavishly. I wrote my own ComboBox widget for Java because the native one is so ugly.
Nothing here that can't be achieved in PureBasic. Not in 800 lines though.
I'm just using the free version as proof-of-concept. But since 80 clams is 80 clams, I do want to know before I spend. While I can do some clever colon tricks, I doubt I can compress 5,000+LOC into 800... Or, can I? :mrgreen:
You could look at something like Embarcadero Delphi which is an OOP langauge and might be less of a culture shock for you. But if you're worried about the price of PureBasic, the price of Delphi will probably be a shock!
Delphi is absurdly expensive for me. I have FreePascal, but it is native widgets under the hood, as well. While I would get free Classes/Objects, they're not really necessary since I'm used to structures & associated functions in C. Besides, I like the PB IDE far more than Lazarus and PB, aside from a few oddities such as List behavior, looks and feels like Pascal in many ways. I'm assuming PB uses a single-pass compiler like Pascal?

Anyway, if I decide to take the plunge, I will have to reconsider many design decisions.
User avatar
mk-soft
Always Here
Always Here
Posts: 6579
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Newbie!] Pointers and Multi-Windows

Post by mk-soft »

What makes PureBasic so slangy is the full use of the OS-specific GUI, without external libraries or framework.

Yes, PureBasic has used a single pass compiler either ASM backend or C backend
What I like about PureBasic is its clear sequential programming and a great treasure trove of libraries for everything possible.
GUI, network, JSON, XML to name a few.
The ability to work with pointers, structures and memories (which has a similarity of 'C')

Maybe take a look here. PureBasic: the Quiet Survivor
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

Re: [Newbie!] Pointers and Multi-Windows

Post by syntonica »

mk-soft wrote: Sat Feb 07, 2026 10:44 pm What makes PureBasic so slangy is the full use of the OS-specific GUI, without external libraries or framework.

Yes, PureBasic has used a single pass compiler either ASM backend or C backend
What I like about PureBasic is its clear sequential programming and a great treasure trove of libraries for everything possible.
GUI, network, JSON, XML to name a few.
The ability to work with pointers, structures and memories (which has a similarity of 'C')

Maybe take a look here. PureBasic: the Quiet Survivor
That article describes my thought process and journey to a T. I see more benrefits using PB over FreePascal or Delphi. I've tried both of those and foud them unwieldy (GBs of stuff...) and FB is made up of copious jank trying to be compatible with everything.

My only read complaint about the PB as a language is the proliferation of similar procedure names, like End, EndIf, EndProcedure, &c. I find it annoying, although others may enjoy the specificty of it. Well, actually calling variables Protected vs. Local is a bit annoying, too. However, PB seems to have a large breadth of features, but not always the depth I'm looking for. I have noticed that it favors the Windows Way of Doing Things[tm] and shoehorns in the other OSes, but theres something to be said for the Windows Event queue over Cocoa's supplied callbacks.

There's one C++ framework I've been looking at, UPP, which produces small binaries with static linking and similar LAF across platforms. There's just one problem. There's a bug with with TheIDE bundled: kerning on monospace fonts is brokem. :shock: I'm not sure how you get that wrong. :lol:
User avatar
mk-soft
Always Here
Always Here
Posts: 6579
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Newbie!] Pointers and Multi-Windows

Post by mk-soft »

I didn't notice that in the PB-IDE Monospace should not go. Probably because I've been using another monospace character set for years. Or do you mean something else.

PureBasic was the first to be developed for Amiga. Then Windows can, then Linux, later came macOS. With the development of C-backend came the Raspberry (Linux for ARM). Here you can also run on a macOS with M1- M4 Linux for ARM as a VM and run the PB version for Raspberry.
How PureBasic realizes the user interface to our program in the background for which our application is not relevant at first. It's the same for everyone.
Only when we wanted to do more than the standard do we have to deal with the different operating systems.
Windows Messages, macOS Delegate, Linux g_signal_connect.

When I switched from Windows to macOS, I simply compiled my PB code to my first Mac Mini 2012 and it also ran immediately.
For subtleties of the different OS there is the compiler option (CompilerIf, CompilerSelect, etc)
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
Post Reply