[Gambas-user] RE: Gambas-user Digest, Vol 39, Issue 22

Doriano Blengino doriano.blengino at ...1909...
Sun Aug 9 17:15:05 CEST 2009


Swee Kwang Tan ha scritto:
> Following code is my program, its has the "ilegal instruction" bug.
> In the main class
> PUBLIC SUB Main()
>           DIM fd AS FlowData
>           DIM at AS ShiXing
>           at = NEW ShiXing(fd)
>     
> END
>
> In the FlowData class
> PUBLIC CONST ZhengYin AS Integer = 0
> PUBLIC CONST BiJian AS Integer = 1 
> PUBLIC CONST JieCai AS Integer = 2
> PUBLIC CONST ShiShen AS Integer = 3
> PUBLIC CONST ShangGuan AS Integer = 4
> PUBLIC CONST PianCai AS Integer = 5
> PUBLIC CONST ZhengCai AS Integer = 6
> PUBLIC CONST QiSha AS Integer = 7
> PUBLIC CONST ZhengGuan AS Integer = 8
> PUBLIC CONST PianYin AS Integer = 9
>
> In the ShiXing Class
> ' Gambas class file
> PRIVATE fd AS FlowData
> STATIC tk0 AS Integer[] = [fd.ShangGuan, fd.JieCai, fd.BiJian, fd.PianCai, fd.PianYin, fd.ZhengYin, fd.QiSha, fd.ZhengGuan, fd.JieCai, fd.ZhengYin]
> STATIC tk1 AS Integer[] = [fd.BiJian, fd.JieCai, fd.ShiShen, fd.ShangGuan, fd.PianCai, fd.ZhengCai, fd.QiSha, fd.ZhengGuan, fd.PianYin, fd.ZhengYin]
> STATIC tk2 AS Integer[] = [fd.ShiShen, fd.ShangGuan, fd.PianCai, fd.ZhengCai, fd.PianYin, fd.ZhengYin, fd.QiSha, fd.ZhengGuan, fd.BiJian, fd.JieCai]
> STATIC tk3 AS Integer[] = [fd.PianCai, fd.QiSha, fd.PianYin, fd.ZhengYin, fd.ShangGuan, fd.ZhengCai, fd.JieCai, fd.BiJian, fd.ShiShen, fd.ZhengGuan]
> STATIC tk4 AS Integer[] = [fd.ShangGuan, fd.JieCai, fd.BiJian, fd.PianCai, fd.PianYin, fd.ZhengYin, fd.QiSha, fd.ZhengGuan, fd.JieCai, fd.ZhengYin]
> STATIC tk5 AS Integer[] = [fd.BiJian, fd.JieCai, fd.ShiShen, fd.ShangGuan, fd.PianCai, fd.ZhengCai, fd.QiSha, fd.ZhengGuan, fd.PianYin, fd.ZhengYin]
> STATIC tk6 AS Integer[] = [fd.ShiShen, fd.ShangGuan, fd.PianCai, fd.ZhengCai, fd.PianYin, fd.ZhengYin, fd.QiSha, fd.ZhengGuan, fd.BiJian, fd.JieCai]
> STATIC tk7 AS Integer[] = [fd.PianCai, fd.QiSha, fd.PianYin, fd.ZhengYin, fd.ShangGuan, fd.ZhengCai, fd.JieCai, fd.BiJian, fd.ShiShen, fd.ZhengGuan]
> STATIC tk8 AS integer[] = [fd.ShangGuan, fd.JieCai, fd.BiJian, fd.PianCai, fd.PianYin, fd.ZhengYin, fd.QiSha, fd.ZhengGuan, fd.JieCai, fd.ZhengYin]
> STATIC tk9 AS Integer[] = [fd.BiJian, fd.JieCai, fd.ShiShen, fd.ShangGuan, fd.PianCai, fd.ZhengCai, fd.QiSha, fd.ZhengGuan, fd.PianYin, fd.ZhengYin]
>
> PUBLIC SUB _new(fd1 AS FlowData)
>         fd = fd1
>   
>   
> END
> And I don't need to write it  like this, I' ve a perfect solution to write.
>   
I think that in Main(), when you do

          at = NEW ShiXing(fd)

you are creating a new instance of ShiXing, passing the "fd" which is 
NULL. Then the new "ShiXing" tries to refer to fd, thinking it is an 
object, but it is not because it is NULL. This should raise some Gambas 
error, but not an Illegal Instruction.

I also notice that the class FlowData only contains constants; if it is 
so, then there is no need to use a class - better to use a module. This 
is an argument I don't understand much, but your way to do seems 
erroneous to me. In ShiXing._new() you assign fd=fd1: there is collision 
as fd is both a name of class, and an instance of an object. Again, I 
don't know how this should be interpreted, but my idea is it should be 
forbidden, and you should avoid it, and Gambas should refuse 
compilation. But you use this strange form, Gambas does not catch it as 
an error nor during compilation and nor during runtime, and something 
strange happens. This is matter for Benoit...

Hope this explains a little more...

Regards,

-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."





More information about the User mailing list