home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / pascal / 4937 < prev    next >
Encoding:
Internet Message Format  |  1992-08-20  |  2.9 KB

  1. Path: sparky!uunet!kithrup!hoptoad!decwrl!mips!darwin.sura.net!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!matt.ksu.ksu.edu!news
  2. From: holland@matt.ksu.ksu.edu (Rich Holland)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Records and strings
  5. Date: 20 Aug 1992 18:06:42 -0500
  6. Organization: Kansas State University
  7. Lines: 87
  8. Message-ID: <1718i2INN2os@matt.ksu.ksu.edu>
  9. NNTP-Posting-Host: matt.ksu.ksu.edu
  10. Keywords: Help!
  11.  
  12. I'm having a problem and it seems there's a simple solution, but I can't
  13. seem to grasp it right away...here goes:
  14.  
  15. I've got something like this globally:
  16.  
  17. TYPE  ARecord = Record
  18.         field1 : string[5];
  19.         field2 : string[12];
  20.         field3 : string[17];
  21.         :
  22.         :
  23.         field17: string[7];
  24.         end;
  25.  
  26. Var Rec : Record;
  27.  
  28. Now, I need to validate each field, and I've got a bunch of procedures     
  29. to do this that look like this:
  30.  
  31. Function ValField1(s:string) : Boolean;
  32. Function ValField2(s:string) : Boolean;
  33. :
  34. Function ValField17(s:string): Boolean;
  35.  
  36. Now, I have to use a 'string' in there because of another place in the
  37. program that's calling the validation routines...
  38.  
  39. But what I need to do now is validate ALL the fiellds in a function
  40. like this:
  41.  
  42. Function ValidRecord(ARec : ARecord) : Boolean;
  43.  
  44. I'm trying to call them all, and the best way I could think of was to
  45. write a function to return the field as a string, based on an index:
  46.  
  47. Function Field2String(ARec : Record,i : Integer) : String;
  48. Begin
  49.   Case i of 
  50.     1 : Field2String:=ARec.Field1;
  51.     2 : Field2String:=ARec.Field2;
  52.     :
  53.     :
  54.    17 : Field2String:=ARec.Field17;
  55.    Else FatalError('Invalid Index in Field2String');
  56.  
  57. Now in my ValidRecord() function call, I tried to do something like this:
  58.  
  59. Function ValidRecord(ARec : ARecord) : Boolean;
  60. Var Tmp : Boolean;  { temporary results }
  61. Begin
  62.   Tmp := True;
  63.   If Not ValField1(Field2String(ARec,1)) then Tmp:=False
  64.   Else If Not ValField2(Field2String(ARec,2)) then Tmp:=False
  65.   :
  66.   : 
  67.   Else If Not ValField17(Field2String(ARec,17)) then Tmp:=False;
  68.   ValidRecord:=Tmp;
  69. End; { ValidRecord }
  70.  
  71. My problem:  I get Error 122: Invalid variable reference.
  72.  
  73. Help reveals:  This construct follows the syntax of a variable 
  74.                reference, but it does not denote a memory
  75.                location.  Most likely, you are calling a pointer
  76.                function, but forgetting to dereference the 
  77.                result.
  78.  
  79. Now, why can I call a function like this:
  80.  
  81. s:=Upper(Copy(x,1,5));  { upcase 1st 5 letters of x }                     
  82.  
  83. Copy is a function.
  84. Upper is a function.
  85.  
  86. So is Field2String.
  87. So is ValField.
  88.  
  89. Why can I call a function with another as an argument in one case but
  90. not another?  *groan*
  91.  
  92.  -- Rich
  93.  
  94. -- 
  95. Rich Holland              | INTERNET: holland@matt.ksu.ksu.edu
  96. 100 Jardine Terr, Apt A7  | BITNET  : holland@ksuvm
  97. Manhattan, KS  66502-3357 | UUCP    : ...!rutgers!matt.ksu.ksu.edu!holland
  98. "Jesus saves...but Gretzky gets the rebound!  He shoots!  He scores!!"
  99.