Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Typed Constant Record

Status
Not open for further replies.

Actor

Programmer
Nov 19, 2003
20
US
I want to create an array of records and have it be a typed constant, I've tried the following:
Code:
Type
     ElementType = record
          Noun       : String ;
          AtomNum  : Byte ;
          AtomMass : Real
     end ;

Const
     ATOM_TABLE  : Array [0 .. 2] of ElementType =
          (
          ('Hydrogen',  1, 1.00794),
          ('Helium',      2, 4.002602),
          ('Lithium',     3, 6.941)
          )

The compiler gives "Field Identifier Expected" at the first quote. Can something like this be done?
 
I haven't got my Pascal compiler on this machine, but a few thoughts leap out.

The periodic table is quite long, and it's not unlikely you'll want to add extra data (isotope abundancies, melting points, etc.) sooner or later. Had you considered saving all the data to some sort of file, and filling an array of ElementType at run-time?

You could either maintain the data in a text file, which would have the same maintenance as text embedded in a code file (which is basically what you're doing with your typed constant array), or you could maintain it as a file of records of ElementType, which will take a bit more effort to construct in the first place, but is then ridiculously quick and easy to load at run-time. It's also less liable to unwanted change.

Minor point: you might want to define your string length for the names; there aren't many elements that need the full 255 characters.

Incidentally, the file version also means you can put your array on the heap rather than in the data segment, which is where it will end up if it's a typed constant array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top