Defined( ) : new constant #PB_ASM_Symbol

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Defined( ) : new constant #PB_ASM_Symbol

Post by eddy »

Here is a little example of my problem :

Code: Select all

;//// From included file 1

!EXTRN _PB_Gadget_RegisterGadget@16

;//// From included file 2

!EXTRN _PB_Gadget_RegisterGadget@16 
;--->  error message : symbol already defined 
Is it possible to add a new constant for this case ?
#PB_ASM_Symbol

Code: Select all

CompilerIf Defined(_PB_Gadget_RegisterGadget, #PB_ASM_Symbol)=#False
!EXTRN _PB_Gadget_RegisterGadget@16 
CompilerEndIf
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Why not import "PB_Gadget_RegisterGadget" ?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

Why not import "PB_Gadget_RegisterGadget"
It works only for external functions (like _PB_Gadget_RegisterGadget).

But how to import _PB_Gadget_Objects ?
It seems to be a global variable.

Do you know the ASM code to check if symbol exists ?
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

The compiler cannot know what will be going on at the assembly stage.
You have to use FASM conditional directives for this.
quidquid Latine dictum sit altum videtur
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Code: Select all

Import "Gadget.lib"
  CompilerIf #PB_Compiler_Unicode
  PB_Gadget_RegisterGadget(a,b,c,d) As "_PB_Gadget_RegisterGadget_UNICODE@16"
  CompilerElse
  PB_Gadget_RegisterGadget(a,b,c,d) As "_PB_Gadget_RegisterGadget@16"
  CompilerEndIf
EndImport

Import "Gadget.lib"
  PB_Gadget_Objects
EndImport

Debug PB_Gadget_Objects

If OpenWindow(0, 0, 0, 322, 150, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  EditorGadget(0, 8, 8, 306, 133) 
  TextGadget(1,0,0,0,0,"")
  For a = 0 To 5 
    AddGadgetItem(0, a, "Line "+Str(a)) 
  Next 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf 
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

great! It works thx. :)

And if someone needs to know the FASM directives :

Code: Select all

!IF ~ DEFINED _PB_Gadget_RegisterGadget
   !EXTRN _PB_Gadget_RegisterGadget@16
!END IF 
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Post Reply