Another Record Error
Author |
Message |
Justin_
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
Martin
![](http://www.compsci.ca/wiki/images/4/46/CanadianStickUp.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Justin_
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: 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 Smile](http://compsci.ca/v3/images/smiles/icon_smile.gif) |
|
|
|
|
![](images/spacer.gif) |
|
|