[Gambas-user] #11 and a bug in the editor
mike-nought at ...17...
mike-nought at ...17...
Sun Aug 6 07:49:26 CEST 2006
Hi Benoit, hi all.
I am currently writing a quite large project (an ID3-Tagger) with the
development version and discovered Gambas not to behave as it should at two
points. Here is the function I wanted to use for merging several objects (of
the same type), keeping those values which are same and resetting all others:
PUBLIC FUNCTION merge(values AS Object[]) AS Object
DIM o AS Object
DIM i AS Variant
DIM x AS Boolean
DIM result AS Object
DIM t AS String
DIM v1 AS Variant
DIM v2 AS Variant
IF values.Count = 0 THEN RETURN NULL
t = Object.Type(values[0])
' (1) this SELECT CASE should be replacable with result=New(t)
SELECT CASE t
CASE "CMPEGHeader"
result = NEW CMPEGHeader
CASE "CTag"
result = NEW CTag
CASE "CTagv1"
result = NEW CTagv1
CASE "CTagv2"
result = NEW CTagv2
END SELECT
FOR EACH i IN Classes[t].Symbols
FOR EACH o IN values
IF NOT x THEN
TRY Object.SetProperty(result, i, Object.GetProperty(o, i))
x = TRUE
ELSE
v1 = NULL
v2 = NULL
TRY v1 = Object.GetProperty(result, i)
TRY v2 = Object.GetProperty(o, i)
IF NOT (v1 = v2) THEN
TRY Object.SetProperty(result, i, "")
END IF
END IF
NEXT ' (2) interpreter jumps here after RETURN
x = FALSE
NEXT
RETURN result
END
I marked the location of both bugs(?) with (1) and (2).
(1): Here a new instance of the type of the passed objects should be created,
which was formerly possible through result=New(t) in this case. But now this
doesn't work anymore, because the editor replaces New([...]) with NEW ([...])
which I cannot use here.
(2): This is an interesting bug. It causes a #11-error during runtime.
Debugging this function stepwise, I discovered that everything works nicely
until RETURN is reached. Instead of now returning the stuff, the Interpreter
jumps back to the first NEXT (which I marked above), producing this
#11-error.
I don't know, if this bug is reproducable in any project, is anyone able to
reproduce it? If not, I'll send you my application.
Regards,
Franz
P.S. I'm from germany, please forgive me my bad english.
More information about the User
mailing list