Page 1 of 1
Duplicates Imports should be ignored instead of compiler err
Posted: Sun Jul 19, 2020 10:24 am
by Rinzwind
#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).
Re: Duplicates Imports should be ignored instead of compiler
Posted: Sun Jul 19, 2020 12:03 pm
by chi
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.
Re: Duplicates Imports should be ignored instead of compiler
Posted: Sun Jul 19, 2020 1:28 pm
by BarryG
chi wrote:put all imports into a separate file and include them with XIncludeFile "Imports.pbi"
Nice trick!
Re: Duplicates Imports should be ignored instead of compiler
Posted: Wed Jul 29, 2020 3:19 pm
by Josh
chi wrote:Doing otherwise is just bad practice.
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.
Re: Duplicates Imports should be ignored instead of compiler
Posted: Wed Jul 29, 2020 3:50 pm
by Derren
I guess this is not possible, either?
Code: Select all
Import "test.lib"
Test()
EndImport
Import "another.lib"
Test() ; same function name, should throw an error?
EndImport
If so, you can still use Defined?
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
Posted: Wed Jul 29, 2020 4:16 pm
by Josh
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)
Re: Duplicates Imports should be ignored instead of compiler
Posted: Fri Oct 09, 2020 5:42 pm
by GPI
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