PureBasic Forum
http://forums.purebasic.com/english/

My Workaround Collection
http://forums.purebasic.com/english/viewtopic.php?f=12&t=71286
Page 1 of 1

Author:  mk-soft [ Fri Aug 24, 2018 12:25 pm ]
Post subject:  My Workaround Collection

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.

Author:  mk-soft [ Fri Aug 24, 2018 12:26 pm ]
Post subject:  Re: My Workaround Collection

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

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

Author:  mk-soft [ Fri Aug 24, 2018 12:27 pm ]
Post subject:  Re: My Workaround Collection

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

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

Author:  mk-soft [ Fri Aug 24, 2018 12:28 pm ]
Post subject:  Re: My Workaround Collection

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

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

Author:  RSBasic [ Fri Aug 24, 2018 12:31 pm ]
Post subject:  Re: My Workaround Collection

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

Author:  Mijikai [ Fri Aug 24, 2018 1:03 pm ]
Post subject:  Re: My Workaround Collection

Thanks this is useful :)

Author:  mk-soft [ Fri Aug 24, 2018 1:03 pm ]
Post subject:  Re: My Workaround Collection

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

Author:  Sicro [ Sat Aug 25, 2018 5:01 pm ]
Post subject:  Re: My Workaround Collection

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

Author:  RSBasic [ Sun Aug 26, 2018 2:37 pm ]
Post subject:  Re: My Workaround Collection

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

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/