home *** CD-ROM | disk | FTP | other *** search
- // %PARAMETERS = "CH16LIST C:\UT2004"
- //Identifies the package
- //CH16_01LIST.uc
-
- class CH16_01LIST extends Commandlet;
-
- //#1
- //Declaration of struct at class scope
- //An "abstract" data type
- struct Play{
- var string szTitle; //struct members
- var string szAuthor;
- var int iReference;
- var int iCastNumber;
- var string szPrimeChar;
- };
-
- function int Main(string Args){
- //#2
- //Declaration of structure identifiers
- local Play PlayA, PlayB;
-
- //#3
- //Definition of struct members
- PlayA.szTitle = "Electra";
- PlayA.szAuthor = "Sophocles";
- PlayA.iReference = 156;
- PlayA.iCastNumber = 7;
- PlayA.szPrimeChar = "Electra";
-
- PlayB.szTitle = "Oedipus the King";
- PlayB.szAuthor = "Sophocles";
- PlayB.iReference = 99;
- PlayB.iCastNumber = 14;
- PlayB.szPrimeChar = "Iocasta";
-
- Log(Chr(10) $ " CH16_01LIST -- Structures" $ Chr(10));
- //Call of function to display one structure
-
- // #5
- //passing the structs to a function for printing
- showInfo(PlayA);
- showInfo(PlayB);
- return 0;
- }
-
- // #4
- //function receives struct and retrieves members
- function int showInfo(Play playArg){
- local string szLocTitle;
- //Redundant step for demonstration
- //Retrieve member value and assign it to a local identifier
- szLocTitle = Caps(playArg.szTitle);
- Log(Chr(10));
- //Use of local identifier
- Log(" Name of play: " $ szLocTitle );
- //Direct access of other member values
- Log(" szAuthor: " $ playArg.szAuthor );
- Log(" Page ref: " $ playArg.iReference );
- Log(" Number in cast: " $ playArg.iCastNumber );
- Log(" Character example: " $ playArg.szPrimeChar );
- return 0;
- }
-