Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Another Record Error
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Justin_




PostPosted: Fri Jan 20, 2006 6:39 am   Post subject: Another Record Error

code:

    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?
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Fri Jan 20, 2006 9:06 am   Post subject: (No subject)

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:

code:

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




PostPosted: Fri Jan 20, 2006 9:14 am   Post subject: (No subject)

If you know how to use them, a class is a better solution than using a record.
Justin_




PostPosted: Fri Jan 20, 2006 11:24 am   Post subject: (No subject)

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




PostPosted: Fri Jan 20, 2006 11:48 am   Post subject: (No subject)

Read Cervantes Tut on it. It's a long haul, but it will introduce you and guide you through a fair deal.
Cervantes




PostPosted: Fri Jan 20, 2006 5:11 pm   Post subject: (No subject)

The other way of doing it is:
code:

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:
code:

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. Smile
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: