Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Files and types and dynamic arrays


Here is a chunk of me type code;

//record storing details of bowlers for match stats
type Bowlinfo = record
ID : integer;
firstname : string[50]; //needed incase bowler leaves leaque(deleted);
surname : string[50]; //needed incase bowler leaves leaque(deleted);
gamescores : array[1..6] of integer;
end;

//record to store match details and stats
type MatchInfo = record
ID1 : integer;
team1name : string[50]; //needed incase team leaves league(deleted)
team1 : array[1..6] of bowlinfo; //max of 6 bowlers per team per match
ID2 : Integer;
team2name : string[50]; //needed incase team leaves league(deleted)
team2 : array[1..6] of bowlinfo; //max of 6 bowlers per team per match
end;

var matchfile : matchinfo;

My question is that if i want to have a dynamic array in either of the types the code will not compile as the file type is not definite... this is limiting me to make choices now on the maximum number of bowelers per game and max number of games each bowler can play.

Could anyone suggest an alternate method for me to have a file storing match details with dynamic arrays for team1 , team2 and gamescores?

Cheers Der_Ranga

Comments

  • zibadianzibadian Posts: 6,349Member
    :
    : Here is a chunk of me type code;
    :
    : //record storing details of bowlers for match stats
    : type Bowlinfo = record
    : ID : integer;
    : firstname : string[50]; //needed incase bowler leaves leaque(deleted);
    : surname : string[50]; //needed incase bowler leaves leaque(deleted);
    : gamescores : array[1..6] of integer;
    : end;
    :
    : //record to store match details and stats
    : type MatchInfo = record
    : ID1 : integer;
    : team1name : string[50]; //needed incase team leaves league(deleted)
    : team1 : array[1..6] of bowlinfo; //max of 6 bowlers per team per match
    : ID2 : Integer;
    : team2name : string[50]; //needed incase team leaves league(deleted)
    : team2 : array[1..6] of bowlinfo; //max of 6 bowlers per team per match
    : end;
    :
    : var matchfile : matchinfo;
    :
    : My question is that if i want to have a dynamic array in either of the types the code will not compile as the file type is not definite... this is limiting me to make choices now on the maximum number of bowelers per game and max number of games each bowler can play.
    :
    : Could anyone suggest an alternate method for me to have a file storing match details with dynamic arrays for team1 , team2 and gamescores?
    :
    : Cheers Der_Ranga
    :
    You can use an untyped file or a TFileStream for this. Then you are free to develop (is also required) your own file format. This type of coding is not very simple, but is very flexible. A good idea is to make TMatchInfo into an object, which handles all the necessary memory management and file I/O. This way you can later concentrate on the program itself.
  • KoppisKoppis Posts: 68Member
    :
    : Here is a chunk of me type code;
    :
    : //record storing details of bowlers for match stats
    : type Bowlinfo = record
    : ID : integer;
    : firstname : string[50]; //needed incase bowler leaves leaque(deleted);
    : surname : string[50]; //needed incase bowler leaves leaque(deleted);
    : gamescores : array[1..6] of integer;
    : end;
    :
    : //record to store match details and stats
    : type MatchInfo = record
    : ID1 : integer;
    : team1name : string[50]; //needed incase team leaves league(deleted)
    : team1 : array[1..6] of bowlinfo; //max of 6 bowlers per team per match
    : ID2 : Integer;
    : team2name : string[50]; //needed incase team leaves league(deleted)
    : team2 : array[1..6] of bowlinfo; //max of 6 bowlers per team per match
    : end;
    :
    : var matchfile : matchinfo;
    :
    : My question is that if i want to have a dynamic array in either of the types the code will not compile as the file type is not definite... this is limiting me to make choices now on the maximum number of bowelers per game and max number of games each bowler can play.
    :
    : Could anyone suggest an alternate method for me to have a file storing match details with dynamic arrays for team1 , team2 and gamescores?
    :
    : Cheers Der_Ranga
    :
    Use TFileStream and TWriter. With TWriter you can easily write strings and integers to file. Just use WriteString to write string and so on. You can also add WriteListBegin and WriteListEnd to mark parts of the file, so its easier to read the contents back.
Sign In or Register to comment.