It is currently Thu Dec 12, 2019 4:03 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: My Workaround Collection
PostPosted: Fri Aug 24, 2018 12:25 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2057
Location: Germany
Purebasic is my favorite development environment and I also create professional applications and tools.

Even if Purebasic has few bugs, they do occur. For these, however, there is usually a simple solution to fix until the next release via a workaround.

I cleaned up and summarized my workaround, because I can't find most of them myself.
Furthermore, the workaround are rewritten as modules, so that they can be used more easily in the module

This workaround should always be cross-platform and easy to extend.

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Fri Aug 24, 2018 12:34 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: My Workaround Collection
PostPosted: Fri Aug 24, 2018 12:26 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2057
Location: Germany
Workaround-560.pb
Code:
;-TOP

; Workaround PB v5.60
; Version : v1.0
; Create  : 24.08.2018
; Update  :

; -----------------------------------------------------------------------------

;- Global

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_MacOS
    ;TODO
   
  CompilerCase #PB_OS_Windows
    ;TODO
   
  CompilerCase #PB_OS_Linux
    ; Ubuntu Compiler bug
    ImportC "-no-pie" : EndImport
   
CompilerEndSelect

; -----------------------------------------------------------------------------

;- Module

DeclareModule __Workaround
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
      Declare FixResizeGadget(Gadget, x, y, width, height)
      Declare FixSetGadgetFont(Gadget, FontID)
      Declare FixAddGadgetItem(Gadget, Position, Text.s, Image=0, Flags=0)
     
    CompilerCase #PB_OS_Windows
      ;TODO
     
    CompilerCase #PB_OS_Linux
      Declare FixWriteData(file, *adress, length)
     
  CompilerEndSelect
 
EndDeclareModule

Module __Workaround
 
  EnableExplicit
 
  CompilerSelect #PB_Compiler_OS
     
    CompilerCase #PB_OS_MacOS
     
      ; Link https://www.purebasic.fr/english/viewtopic.php?f=24&t=71269
      ; Canvas Gadget Container Bugfix
      Procedure FixResizeGadget(Gadget, x, y, width, height)
        ResizeGadget(Gadget, x, y, width, height)
        Protected rect.NSRect, sv, container
        If GadgetType(Gadget) <> #PB_GadgetType_Canvas
          ProcedureReturn 1
        EndIf
        sv = CocoaMessage(0, GadgetID(Gadget), "subviews")
        If CocoaMessage(0, sv, "count")
          container = CocoaMessage(0, sv, "objectAtIndex:", 0)
          If container
            CocoaMessage(@rect, GadgetID(Gadget), "frame")
            rect\origin\x = 0
            rect\origin\y = 0
            CocoaMessage(0, container, "setFrame:@", @rect)
          EndIf
        EndIf
      EndProcedure
     
      ; Link http://www.purebasic.fr/english/viewtopic.php?f=24&t=68571
      Procedure FixSetGadgetFont(Gadget, FontID)
        SetGadgetFont(Gadget, #PB_Default)
        SetGadgetFont(Gadget, FontID)
      EndProcedure
     
      ; Link http://www.purebasic.fr/english/viewtopic.php?f=24&t=68494
      Procedure FixAddGadgetItem(Gadget, Position, Text.s, Image=0, Flags=0)
        Protected font
        AddGadgetItem(Gadget, Position, Text, Image, Flags)
        If GadgetType(Gadget) = #PB_GadgetType_Editor
          font = GetGadgetFont(Gadget)
          If font
            SetGadgetFont(Gadget, font)
          EndIf
        EndIf
      EndProcedure
     
    CompilerCase #PB_OS_Windows
      ;TODO
     
    CompilerCase #PB_OS_Linux
     
      ; Link http://www.purebasic.fr/english/viewtopic.php?f=23&t=68630
      Procedure FixWriteData(file, *adress, length) ; Workaround for Linux PB560
        Protected write_data_pointer=Loc(file)
        Protected writen_data=WriteData(file, *adress, length)
        FileSeek(file, write_data_pointer+writen_data)
        ProcedureReturn writen_data
      EndProcedure
     
  CompilerEndSelect
 
EndModule

; -----------------------------------------------------------------------------

;- Macro

DeclareModule Workaround
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
      Macro ResizeGadget(Gadget, x, y, width, height)
        __Workaround::FixResizeGadget(Gadget, x, y, width, height)
      EndMacro
     
      Macro SetGadgetFont(Gadget, FontID)
        __Workaround::FixSetGadgetFont(Gadget, FontID)
      EndMacro
     
      Macro AddGadgetItem(Gadget, Position, Text, Image=0, Flags=0)
        __Workaround::FixAddGadgetItem(Gadget, Position, Text, Image, Flags)
      EndMacro
     
    CompilerCase #PB_OS_Windows
      ;TODO
     
    CompilerCase #PB_OS_Linux
      Macro WriteData(File, Buffer, Size)
        __Workaround::FixWriteData(File, Buffer, Size)
      EndMacro
     
  CompilerEndSelect
EndDeclareModule

Module Workaround
EndModule

; -----------------------------------------------------------------------------

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: My Workaround Collection
PostPosted: Fri Aug 24, 2018 12:27 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2057
Location: Germany
Workaround-562.pb
Code:
;-TOP

; Workaround PB v5.62
; Version : v1.0
; Create  : 24.08.2018
; Update  :

; -----------------------------------------------------------------------------

;- Global

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_MacOS
    ;TODO
   
  CompilerCase #PB_OS_Windows
    ;TODO
   
  CompilerCase #PB_OS_Linux
    ; Ubuntu compiler bug
    ImportC "-no-pie" : EndImport
   
CompilerEndSelect

; -----------------------------------------------------------------------------

;- Module

DeclareModule __Workaround
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
      Declare FixResizeGadget(Gadget, x, y, width, height)
     
    CompilerCase #PB_OS_Windows
      ;TODO
     
    CompilerCase #PB_OS_Linux
      ;TODO
  CompilerEndSelect
 
EndDeclareModule

Module __Workaround
 
  EnableExplicit
 
  CompilerSelect #PB_Compiler_OS
     
    CompilerCase #PB_OS_MacOS
     
      ; Link https://www.purebasic.fr/english/viewtopic.php?f=24&t=71269
      ; Canvas Gadget Container Bugfix
      Procedure FixResizeGadget(Gadget, x, y, width, height)
        ResizeGadget(Gadget, x, y, width, height)
        Protected rect.NSRect, sv, container
        If GadgetType(Gadget) <> #PB_GadgetType_Canvas
          ProcedureReturn 1
        EndIf
        sv = CocoaMessage(0, GadgetID(Gadget), "subviews")
        If CocoaMessage(0, sv, "count")
          container = CocoaMessage(0, sv, "objectAtIndex:", 0)
          If container
            CocoaMessage(@rect, GadgetID(Gadget), "frame")
            rect\origin\x = 0
            rect\origin\y = 0
            CocoaMessage(0, container, "setFrame:@", @rect)
          EndIf
        EndIf
      EndProcedure
     
    CompilerCase #PB_OS_Windows
      ;TODO
     
    CompilerCase #PB_OS_Linux
      ;TODO
  CompilerEndSelect
 
EndModule

; -----------------------------------------------------------------------------

;- Macro

DeclareModule Workaround
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
      Macro ResizeGadget(Gadget, x, y, width, height)
        __Workaround::FixResizeGadget(Gadget, x, y, width, height)
      EndMacro
    CompilerCase #PB_OS_Windows
      ;TODO
    CompilerCase #PB_OS_Linux
      ;TODO
  CompilerEndSelect
EndDeclareModule

Module Workaround
EndModule

; -----------------------------------------------------------------------------

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: My Workaround Collection
PostPosted: Fri Aug 24, 2018 12:28 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2057
Location: Germany
Base for extended workaround

Workaround-Empty.pb
Code:
;-TOP

; Workaround PB Empty
; Version : v1.0
; Create  : 24.08.2018
; Update  :

; -----------------------------------------------------------------------------

;- Global

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_MacOS
    ;TODO
   
  CompilerCase #PB_OS_Windows
    ;TODO
   
  CompilerCase #PB_OS_Linux
    ;TODO
   
CompilerEndSelect

; -----------------------------------------------------------------------------

;- Module

DeclareModule __Workaround
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
      ;TODO
     
    CompilerCase #PB_OS_Windows
      ;TODO
     
    CompilerCase #PB_OS_Linux
      ;TODO
  CompilerEndSelect
 
EndDeclareModule

Module __Workaround
 
  EnableExplicit
 
  CompilerSelect #PB_Compiler_OS
     
    CompilerCase #PB_OS_MacOS
      ;TODO
     
    CompilerCase #PB_OS_Windows
      ;TODO
     
    CompilerCase #PB_OS_Linux
      ;TODO
  CompilerEndSelect
 
EndModule

; -----------------------------------------------------------------------------

;- Macro

DeclareModule Workaround
  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
      ;TODO
     
    CompilerCase #PB_OS_Windows
      ;TODO
     
    CompilerCase #PB_OS_Linux
      ;TODO
     
  CompilerEndSelect
EndDeclareModule

Module Workaround
EndModule

; -----------------------------------------------------------------------------

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Fri Aug 24, 2018 12:55 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: My Workaround Collection
PostPosted: Fri Aug 24, 2018 12:31 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1108
Location: Berlin (Germany)
Good idea Image

At home I also have a few workarounds.

1 workaround for FTP text conversion:
Code:
Procedure.s AsciiToUTF8(String$)
  Protected Buffer$
 
  Buffer$ = Space(Len(String$))
  PokeS(@Buffer$, String$, -1, #PB_Ascii)
  String$ = PeekS(@Buffer$, -1, #PB_UTF8)
 
  ProcedureReturn String$
EndProcedure

Or with my library: viewtopic.php?f=27&t=70380

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
 Post subject: Re: My Workaround Collection
PostPosted: Fri Aug 24, 2018 1:03 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 577
Thanks this is useful :)


Top
 Profile  
Reply with quote  
 Post subject: Re: My Workaround Collection
PostPosted: Fri Aug 24, 2018 1:03 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2057
Location: Germany
Thanks,

My goal is to have a workaround that can always be changed with the next release of purebasic without changing the other code.

I've dropped an empty workaround so that I can add tested code more easily,
or use a separate workaround for certain libraries if needed. For example WorkaroundFTP.pb

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: My Workaround Collection
PostPosted: Sat Aug 25, 2018 5:01 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 376
Location: Germany
You could additionally check the constant #PB_Compiler_Version, so that the correct workarounds are used for each PB version:
Code:
CompilerSelect #PB_Compiler_Version
  CompilerCase 560 : XIncludeFile "Workarounds-560.pbi"
  CompilerCase 562 : XIncludeFile "Workarounds-562.pbi"
  Default          : XIncludeFile "Workarounds-All.pbi"
CompilerEndSelect

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: My Workaround Collection
PostPosted: Sun Aug 26, 2018 2:37 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 1108
Location: Berlin (Germany)
Workaround for FileSize():
FileSize() (FindFirstFile_()) in Windows supports wildcards. :?
But I don't want that, because I want to know exactly with the given file name whether the file with the exact file name exists.
Solution code:
Code:
Procedure FileSizeEx(FileName$)
  Protected p
 
  FileName$ = ReplaceString(FileName$, "*", "_")
  FileName$ = ReplaceString(FileName$, "?", "_")
  FileName$ = ReplaceString(FileName$, "<", "_")
  FileName$ = ReplaceString(FileName$, ">", "_")
  FileName$ = ReplaceString(FileName$, Chr(34), "_")
 
  If FileSize(FileName$) <> -2
    p = Len(FileName$)
    While p >= 1 And FindString("/\", Mid(FileName$, p, 1)) <> 0
      p-1
    Wend
    If Len(FileName$) <> Len(Left(FileName$, p))
      FileName$ + "_"
    EndIf
  EndIf
 
  ProcedureReturn FileSize(FileName$)
EndProcedure

Macro FileSize(FileName)
  FileSizeEx(FileName)
EndMacro

_________________
ImageImageImageImage Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye