Question about mdTypes

New to FreeBASIC? Post your questions here.
Post Reply
PeterHu
Posts: 161
Joined: Jul 24, 2022 4:57

Question about mdTypes

Post by PeterHu »

Coding with mdTypes https://www.freebasic-portal.de/tutoria ... 08-s3.html as below,it works great,but when I uncommented lines marked as #1,#2,#3 and #4,the compiler produced a lot of errors.I have no clue what happened behind.Is it something related to macros?

Thanks for the help in advance.
errors:

Code: Select all

16:26:15: Compilation: "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\fbc32.exe"  -b "mdemu01.bas" -exx -v -v  -i "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\MariaDBBox" -p "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\MariaDBBox" -i "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\MyFbFramework" -p "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\MyFbFramework\lib/win-x86" -i "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\SQLite3" -p "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\SQLite3" -i ".\Controls\MyFbFramework\inc" -p ".\Controls\MyFbFramework\Lib" -d _DebugWindow_=12522342

16:26:15: FreeBASIC Compiler - Version 1.20.0 (2023-12-04), built for win32 (32bit) 
16:26:15: Copyright (C) 2004-2023 The FreeBASIC development team. 
16:26:15: standalone 
16:26:15: target :       win32, 686, 32bit
16:26:15: backend :      gas
16:26:15: compiling :    mdemu01.bas -o mdemu01.asm (main module)
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(8) error 4: Duplicated definition, mdListPtr in '#Define mdListPtr(E, P) mdList##E##P'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(9) error 4: Duplicated definition, mdList in '#Define mdList(E, P...) mdListPtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(11) error 4: Duplicated definition, mdListDeclarePtr in '#Macro mdListDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 14: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 14: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 14: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 59: Illegal specification, at parameter 1 (element) of MDCOLLECTIONEP.constructor stdcall() in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 59: Illegal specification, at parameter 1 (element) of add() in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 59: Illegal specification, at parameter 1 (o) of contains() in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 14: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E,P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 133: Too many errors, exiting

16:26:15: Found Errors (11 Pos).
16:26:15: Do not build file. Elapsed Time: 0.20 Seconds




Error: Duplicated definition, mdListPtr in '#Define mdListPtr(E, P) mdList##E##P'
Error: Duplicated definition, mdList in '#Define mdList(E, P...) mdListPtr(E, P)'
Error: Duplicated definition, mdListDeclarePtr in '#Macro mdListDeclarePtr(E, P)'
Error: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
Error: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
Error: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
Error: Illegal specification, at parameter 1 (element) of MDCOLLECTIONEP.constructor stdcall() in 'mdCollectionDeclarePtr(E, P)'
Error: Illegal specification, at parameter 1 (element) of add() in 'mdCollectionDeclarePtr(E, P)'
Error: Illegal specification, at parameter 1 (o) of contains() in 'mdCollectionDeclarePtr(E, P)'
Error: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, )'
Error: Too many errors, Exit

commented lines #1-#4:

Code: Select all


'#include once "md/util/mdList.bi"               '#1
'#include once "md/util/mdArrayIterator.bi"      '#2

#include once "md/util/mdEnumeration.bi"

'mdListDeclare(string)                           '#3
'mdArrayIteratorDeclare(string)                  '#4

mdEnumerationDeclare(string)

dim as mdList(string) list
list.add("one")
list.add("two")
list.add("three")

dim as mdEnumeration(string) ele= list
while ele.hasMoreElements()
	print ele.nextElement
	
wend

sleep
Xusinboy Bekchanov
Posts: 799
Joined: Jul 26, 2018 18:28

Re: Question about mdTypes

Post by Xusinboy Bekchanov »

PeterHu wrote: Mar 28, 2024 8:23 Coding with mdTypes https://www.freebasic-portal.de/tutoria ... 08-s3.html as below,it works great,but when I uncommented lines marked as #1,#2,#3 and #4,the compiler produced a lot of errors.I have no clue what happened behind.Is it something related to macros?

Thanks for the help in advance.
errors:

Code: Select all

16:26:15: Compilation: "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\fbc32.exe"  -b "mdemu01.bas" -exx -v -v  -i "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\MariaDBBox" -p "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\MariaDBBox" -i "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\MyFbFramework" -p "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\MyFbFramework\lib/win-x86" -i "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\SQLite3" -p "E:\Learning\FreeBasic\VisualFBEditor-Nightly\Controls\SQLite3" -i ".\Controls\MyFbFramework\inc" -p ".\Controls\MyFbFramework\Lib" -d _DebugWindow_=12522342

16:26:15: FreeBASIC Compiler - Version 1.20.0 (2023-12-04), built for win32 (32bit) 
16:26:15: Copyright (C) 2004-2023 The FreeBASIC development team. 
16:26:15: standalone 
16:26:15: target :       win32, 686, 32bit
16:26:15: backend :      gas
16:26:15: compiling :    mdemu01.bas -o mdemu01.asm (main module)
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(8) error 4: Duplicated definition, mdListPtr in '#Define mdListPtr(E, P) mdList##E##P'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(9) error 4: Duplicated definition, mdList in '#Define mdList(E, P...) mdListPtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(11) error 4: Duplicated definition, mdListDeclarePtr in '#Macro mdListDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 14: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 14: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 14: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 59: Illegal specification, at parameter 1 (element) of MDCOLLECTIONEP.constructor stdcall() in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 59: Illegal specification, at parameter 1 (element) of add() in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 59: Illegal specification, at parameter 1 (o) of contains() in 'mdCollectionDeclarePtr(E, P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 14: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E,P)'
E:\Learning\FreeBasic\VisualFBEditor-Nightly\Compilers\FreeBASIC-1.20.0-winlibs-gcc-9.3.0\inc\md\util\mdList.bi(13) error 133: Too many errors, exiting

16:26:15: Found Errors (11 Pos).
16:26:15: Do not build file. Elapsed Time: 0.20 Seconds




Error: Duplicated definition, mdListPtr in '#Define mdListPtr(E, P) mdList##E##P'
Error: Duplicated definition, mdList in '#Define mdList(E, P...) mdListPtr(E, P)'
Error: Duplicated definition, mdListDeclarePtr in '#Macro mdListDeclarePtr(E, P)'
Error: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
Error: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
Error: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, P)'
Error: Illegal specification, at parameter 1 (element) of MDCOLLECTIONEP.constructor stdcall() in 'mdCollectionDeclarePtr(E, P)'
Error: Illegal specification, at parameter 1 (element) of add() in 'mdCollectionDeclarePtr(E, P)'
Error: Illegal specification, at parameter 1 (o) of contains() in 'mdCollectionDeclarePtr(E, P)'
Error: Expected identifier, found 'E' in 'mdCollectionDeclarePtr(E, )'
Error: Too many errors, Exit

commented lines #1-#4:

Code: Select all


'#include once "md/util/mdList.bi"               '#1
'#include once "md/util/mdArrayIterator.bi"      '#2

#include once "md/util/mdEnumeration.bi"

'mdListDeclare(string)                           '#3
'mdArrayIteratorDeclare(string)                  '#4

mdEnumerationDeclare(string)

dim as mdList(string) list
list.add("one")
list.add("two")
list.add("three")

dim as mdEnumeration(string) ele= list
while ele.hasMoreElements()
	print ele.nextElement
	
wend

sleep
This is how it works:

Code: Select all

#include once "md/util/mdEnumeration.bi"

#include once "md/util/mdList.bi"               '#1
#include once "md/util/mdArrayIterator.bi"      '#2


mdListDeclare(String)                           '#3
mdArrayIteratorDeclare(String)                  '#4

mdEnumerationDeclare(String)

Dim As mdList(String) list
list.add("one")
list.add("two")
list.add("three")

Dim As mdEnumeration(String) ele= list
While ele.hasMoreElements()
	Print ele.nextElement
	
Wend

Sleep
In your version it did not work, because in this file #include "md/util/mdList.bi" is already declared without #include once, only with #include, so when connecting #include once "md/util/mdEnumeration.bi" third line, wants to re-include this file: "md/util/mdList.bi", so duplicates are obtained:

Code: Select all

'mdEnumeration - by MOD

'http://docs.oracle.com/javase/6/docs/api/java/util/Enumeration.html


#include "md/lang/mdObject.bi"
#include "md/lang/mdString.bi"
#include "md/util/mdList.bi"

#define mdEnumerationPtr(E, P) mdEnumeration##E##P
#define mdEnumeration(E, P...) mdEnumerationPtr(E, P)

#macro mdEnumerationDeclarePtr(E, P)

mdListDeclarePtr(E, P)

#ifndef mdEnumeration##E##P
'#Define __MDENUMERATION_BI__

Type mdEnumeration##E##P Extends mdObject
	Public:
	Declare Constructor ()
	Declare Constructor (ByRef enum_ As mdEnumeration##E##P)
	Declare Constructor (ByRef c As mdCollection##E##P)
	Declare Constructor (ByRef s As String)
	
	Declare Virtual Function getClass() As String
	Declare Virtual Function hasMoreElements() As Boolean
	Declare Virtual Function nextElement() As E P
	
	Protected:
	As mdListPtr(E, P) list
	As mdIteratorPtr(E, P) iterator
	As Integer index
End Type

MODULE_SCOPE Constructor mdEnumeration##E##P()
	
End Constructor

MODULE_SCOPE Constructor mdEnumeration##E##P(ByRef enum_ As mdEnumeration##E##P)
	This.list = enum_.list
	This.iterator = This.list.iterator()
End Constructor

MODULE_SCOPE Constructor mdEnumeration##E##P(ByRef c As mdCollection##E##P)
	This.list.addAll(c)
	This.iterator = This.list.iterator()
End Constructor

MODULE_SCOPE Constructor mdEnumeration##E##P(ByRef s As String)
	Dim As mdString tempString = s
	Dim As String tempArray()
	tempString.split(tempArray(), " ")
	For i As Integer = LBound(tempArray) To UBound(tempArray)
		This.list.add(Cast(E P, tempArray(i)))
	Next
	This.iterator = This.list.iterator()
End Constructor

MODULE_SCOPE Function mdEnumeration##E##P.getClass() As String
	Return UCase("mdEnumeration(" & #E & IIf(Len(#P), ", " & #P, "") & ")")
End Function

MODULE_SCOPE Function mdEnumeration##E##P.hasMoreElements() As Boolean
	Return iterator.hasNext()
End Function

MODULE_SCOPE Function mdEnumeration##E##P.nextElement() As E P
	Return iterator.nex()
End Function

#endif '__MDENUMERATION_BI__

#endmacro

#define mdEnumerationDeclare(E, P...) mdEnumerationDeclarePtr(E, P)
PeterHu
Posts: 161
Joined: Jul 24, 2022 4:57

Re: Question about mdTypes

Post by PeterHu »

Thank you so much!

I added 'once' into mdenumeration.bi as a local update and now it seems everything is great.
Post Reply