Shop OBEX P1 Docs P2 Docs Learn Events
Initializing arrays (FlexBasic 5.9.20) — Parallax Forums

Initializing arrays (FlexBasic 5.9.20)

This (shared) works:
dim shared as ubyte plc(4) = { &h01,&h02,&h03,&h04 }

Not shared gives an error:
dim as ubyte plc(4) = { &h01,&h02,&h03,&h04 }

Not really a problem but just curious.

Comments

  • @Mickster said:
    This (shared) works:
    dim shared as ubyte plc(4) = { &h01,&h02,&h03,&h04 }

    Not shared gives an error:
    dim as ubyte plc(4) = { &h01,&h02,&h03,&h04 }

    Not really a problem but just curious.

    All BASIC files can potentially be used as objects with class using, just like Spin files. Variables declared as shared are shared among all instances of such a class, so there's no difficulty in initializing them (there's only one copy to initialize). However, variables declared without "shared" are different in each class, and each copy would have to be initialized when the class is created (i.e. at run time). Right now there's no notion of a "constructor" in BASIC, so this isn't possible.

    In Spin terms, "shared" variables are in the DAT section (which can be initialized) whereas non-shared variables are in the VAR section (which is always initialized to 0 and cannot be initialized to anything else).

  • pik33pik33 Posts: 2,350

    Right now there's no notion of a "constructor" in BASIC, so this isn't possible.

    You can always write a "manual" constructor for a class - write a method, call it init or something like this and let it initialize the object. Of course this means calling the "constructor" manually before first using the object.

    var an_object=new class_name
    an_object.init(parameters)
    
Sign In or Register to comment.