#Test = 1
#Test = 1
Compiles fine/
Import "test.lib"
Test()
EndImport
Import "test.lib"
Test()
EndImport
is not fine.
When using lots of includes file and grouping related stuff together you can have imports of the same function multiple times. Would be nice if the compiler allows (ignores) this and only complains when the import is actually different from previous one (just like with constants).
Duplicates Imports should be ignored instead of compiler err
Re: Duplicates Imports should be ignored instead of compiler
If you are already dealing with many include files, why not put all imports into a separate file and include them with XIncludeFile "Imports.pbi"? Doing otherwise is just bad practice.
Et cetera is my worst enemy
Re: Duplicates Imports should be ignored instead of compiler
Nice trick!chi wrote:put all imports into a separate file and include them with XIncludeFile "Imports.pbi"
Re: Duplicates Imports should be ignored instead of compiler
No, it's not. If you try to write IncludeFiles, which bring everything they need themselves, then you have a problem. With many other things like Structure or Enumeration you can help yourself with Defined, with Import you do not have these possibilities.chi wrote:Doing otherwise is just bad practice.
sorry for my bad english
Re: Duplicates Imports should be ignored instead of compiler
I guess this is not possible, either?
If so, you can still use Defined?
I'm guessing, since I have no experience with Import and nothing to test this with.
Or do it properly and use Modules?
Either really properly and use one Module for each Library, or just put the same Import in a bunch of Modules over and over again. The functions are then only accessible via the Module. Probably blows your exe size up.
Code: Select all
Import "test.lib"
Test()
EndImport
Import "another.lib"
Test() ; same function name, should throw an error?
EndImport
Code: Select all
Import "test.lib"
Test()
EndImport
CompilerIf Not Defined(Test(), #PB_Procedure ) ; or #PB_Function ?
Import "another.lib"
Test() ; same function name, should throw an error?
EndImport
CompilerEndIf
I'm guessing, since I have no experience with Import and nothing to test this with.
Or do it properly and use Modules?
Either really properly and use one Module for each Library, or just put the same Import in a bunch of Modules over and over again. The functions are then only accessible via the Module. Probably blows your exe size up.
Re: Duplicates Imports should be ignored instead of compiler
Derren, of course you're right. With 'Defined' I always thought about 'Import' and not about the individual procedures. This works, but it doesn't look very good:
Code: Select all
Import "User32.lib"
CompilerIf Not Defined (MessageBoxA, #PB_Procedure)
MessageBoxA (Window.i, Body$, Title$, Flags.i = 0)
CompilerEndIf
CompilerIf Not Defined (MsgBox, #PB_Procedure)
MsgBox (Window.i, Body$, Title$, Flags.i) As "_MessageBoxA@16"
CompilerEndIf
EndImport
Import "User32.lib"
CompilerIf Not Defined (MessageBoxA, #PB_Procedure)
MessageBoxA (Window.i, Body$, Title$, Flags.i = 0)
CompilerEndIf
CompilerIf Not Defined (MsgBox, #PB_Procedure)
MsgBox (Window.i, Body$, Title$, Flags.i) As "_MessageBoxA@16"
CompilerEndIf
EndImport
MessageBoxA(0, "Hello", "World 1")
MsgBox (0, "Hello", "World 2", 0)
sorry for my bad english
Re: Duplicates Imports should be ignored instead of compiler
you can add a check:
Code: Select all
Import "test.lib"
Test()
EndImport
CompilerIf Not Defined(Test,#PB_Procedure)
Import "test.lib"
Test()
EndImport
CompilerEndIf