从 Gambas2 迁移到 Gambas3

该表尝试成为记录Gambas2与Gambas3之间所有不兼容变化的详细目录。

当IDE工程转换器进行自动转换时,会插入以=[GB2:XXXX]=字符串开头的注释,其中=XXXX=是四个字母组成的描述发生何种转换的向导标识符。

向导标识符 表征 详情 Gambas 2 → Gambas 3
ARRD "Syntax error" on array declaration 现在,声明一维数组时必须使用NEW关键字。
DIM sCommand AS String[5]

Dim sCommand As New String[5]
BCOL "Unknown symbol 'BackColor'..." error Control中的BackColor 属性已被删除,用Background来替代。
MyLabel.BackColor = Color.Background

MyLabel.Background = Color.Background
BIND "Too many arguments" error with UdpSocket.Bind() The UdpSocket.Bind() 方法 cannot take a Port argument anymore.

Use the Port property instead.
hBroadcastEvent.Bind(0)

hBroadcastEvent.Port = 0
hBroadcastEvent.Bind()
CLNG "Unknown identifier 'CLng'" error The CLng() function synonymous has been removed.

Use CLong() instead.
CLng(...)

CLong(...)
CSNG "Unknown identifier 'CSng'" error The CSng() function synonymous has been removed.

Use CSingle() instead.
CSng(...)

CSingle(...)
CFLT "Unknown identifier 'CFlt'" error The CFlt() function synonymous has been removed.

Use CFloat() instead.
CFlt(...)

CFloat(...)
DBGV "Unknown symbol 'GridView' in class 'DataBrowser'" error The gridview property of the DataBrowser control has been renamed as View.
DataBrowserLog.GridView

DataBrowserLog.View
DMRG "DrawingArea.Merge is deprecated" warning message The DrawingArea.Merge does nothing anymore. You can remove it.
MyDrawingArea.Merge = TRUE

' Nothing
DSUB SQL errors with database methods Arguments of DB.Exec() and DB.Subst() above nine now must be enclosed with {} now.
MyConnection.Exec("UPDATE devices "
  "SET name = &1, module = &2, "
  "interface = &3, address = &4, "
  "location = &5, label = &6, "
  "label2 = &7, label3 = &8, "
  "value = &9, officon = &10, "
  "onicon = &11")

MyConnection.Exec("UPDATE devices "
  "SET name = &1, module = &2, "
  "interface = &3, address = &4, "
  "location = &5, label = &6, "
  "label2 = &7, label3 = &8, "
  "value = &9, officon = &{10}, "
  "onicon = &{11}")
FCOL "Unknown symbol 'ForeColor'..." error Control中的ForeColor 属性已被删除,用Foreground来替代。
MyLabel.ForeColor = Color.Red

MyLabel.Foreground = Color.Red
FNTH "Not an 对象" error while using Font.Height Font.Height is now a property. The old Font.Height() method has been renamed Font.TextHeight().
Font.Height("text")

Font.TextHeight("text")
FNTW "Unknown symbol 'Width'" error while using Font.Width Font.Width()方法被重命名为Font.TextWidth().
Font.Width("text")

Font.TextWidth("text")
FRMT Unexpected spaces printed with Format$ In Gambas 3, non-used formatting characters in the Format() function are replaced with spaces, whereas they were ignored in Gambas 2.

Just use less formatting characters. Exceeding digits will be printed anyway.
Format(Number, "####")

Format(Number, "#")
IMGS "Too many arguments" error with Image.Stretch() method The Image.Stretch() method does not have its third argument anymore. Remove it.
MyImage = MyImage.Stretch(64, 64, TRUE)

MyImage = MyImage.Stretch(64, 64)
INCB "Boolean incrementation is deprecated" warning message INC Boolean or DEC Boolean isn't allowed anymore. Use Boolean = Not Boolean instead.
INC Boolean
DEC Boolean

Boolean = Not Boolean
ISTY "Type mismatch" error when using IsBoolean(), IsString(), or any Is<Type>() function The Is<Type>() functions have been completely redesigned in Gambas 3. Instead of checking the datatype of an expression, they now check if a string can be safely converted to a specific datatype with the Val() function.

Use TypeOf() to do the check instead.
IF IsBoolean(Value) THEN ...
IF IsByte(Value) THEN ...
IF IsShort(Value) THEN ...
IF IsNumber(Value) THEN ...
...

If TypeOf(Value) = gb.Boolean THEN ...
If TypeOf(Value) = gb.Byte THEN ...
If TypeOf(Value) = gb.Short THEN ...
If TypeOf(Value) <= gb.Float THEN ...
...
OPEN "Unexpected OPEN" error with the OPEN instruction The OPEN instruction syntax has changed.
OPEN sBaseDir &/ "logs" &/ sMainLogFile FOR APPEND AS #hMainLogFile

hMainLogFile = Open sBaseDir &/ "logs" &/ sMainLogFile For Append
OVER "/Class/.*Symbol* is badly overridden in class *OtherClass/" error When you reimplement a symbol in an inherited class, Gambas 3 now checks that the declaration of the symbol in the child class is compatible with the one in the parent class.

Either fix the symbol declaration in the child class, or use another name for that symbol.
' Inside a form
Private Delete As Button

' Inside a form
Private btnDelete As Button
PPRO "Missing AS" error in a property definition using the PUBLIC keyword. The PUBLIC keyword is not allowed anymore in property definitions. Property are always public.
PUBLIC PROPERTY LineColor AS Integer

Property LineColor As Integer
QUES "Unknown identifier 'xxxx?'" error All test functions ending with a question mark have been removed.

Use the synoymous function beginning with "Is" instead.
Dir?(...)
Null?(...)
Integer?(...)
...

IsDir(...)
IsNull(...)
IsInteger(...)
...
QUOT "Unknown identifier 'Quote'" error The quote and Unquote class have been removed.

Replace Quote.Shell by Shell$().
Quote.Shell("...")

Shell$("...")
SLAY "Type mismatch. Integer expected" error with the Splitter.Layout property The Splitter.Layout property now takes an array of integer instead of a string of comma-separated values.
MySplitter.Layout = "500,500"

MySplitter.Layout = [500, 500]
TEXT "gb.Text is deprecated" warning message gb.Text is deprecated and replaced by gb.IgnoreCase.
gb.Text

gb.IgnoreCase

*这些不兼容不会被IDE导入向导自动更改处理。