
-----------------------------------
Justin_
Fri Jan 20, 2006 6:39 am

Another Record Error
-----------------------------------

    var website : flexible array 1 .. 1 of 
        record     %struct equivelant
            url_list    : array 1 .. 20 of string
            %turing doesn't support flexible arrays within records.
            search_found  : int 
            url_count     : int :=0     %To determine how many links there are.
         %   url         : string 
            file_stream   : int
            netStream     : int
            urlNum        : int := 0
        end record 


I'm getting an error, it highlights ":=o" for both urlNum and url_count.  Does this mean I'm initializing my record variables incorrectly?

-----------------------------------
Delos
Fri Jan 20, 2006 9:06 am


-----------------------------------
The elements in a record cannot be initialized directly.  They are basically descriptions of what the variable will contain.  You wouldn't want to initialize them right away anyway - that wouldn't be fun.

You should, however, create a function to initialize them:


type myType :
   record
      name : string
      number : int
      face : string
   end record

function init_MT (inName : string, inNum : int, inFace : string) : myType
   var temp : myType
   temp.name := inName
   temp.number := inNum
   temp.face := inFace
   result temp
end init_MT

% Alternatively, if you do want certain fields to automatically be initialized to a certain value:
function init_MT_def (inName : string) : myType
   var temp : myType
   temp.name := inName
   temp.number := 5
   temp.face := "Sad"
   result temp
end init_MT_def


-----------------------------------
Martin
Fri Jan 20, 2006 9:14 am


-----------------------------------
If you know how to use them, a class is a better solution than using a record.

-----------------------------------
Justin_
Fri Jan 20, 2006 11:24 am


-----------------------------------
Yeah well, my record just so happens to be used in a flexible array, so I really can't see it being too efficient having to initilaize every element inside the array IF it gets created.  

I wish i knew about classes if they could help.

-----------------------------------
Delos
Fri Jan 20, 2006 11:48 am


-----------------------------------
Read Cervantes Tut on it.  It's a long haul, but it will introduce you and guide you through a fair deal.

-----------------------------------
Cervantes
Fri Jan 20, 2006 5:11 pm


-----------------------------------
The other way of doing it is:

var my_coord2d :
    record
        x, y : int
    end record
    := init (5, 7)


I'm fairly certain the above works, though I doubt if it would work on types:

type coord2d :
    record
        x, y : int
    end record
    := init (5, 7)
var my_coord2d : coord2d

I highly doubt that would work, but it's worth a try.  This calls for a new acronym: NOWNOW Not on Windows now

But yes: objects.  :)
