home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!kithrup!hoptoad!decwrl!mips!darwin.sura.net!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!matt.ksu.ksu.edu!news
- From: holland@matt.ksu.ksu.edu (Rich Holland)
- Newsgroups: comp.lang.pascal
- Subject: Records and strings
- Date: 20 Aug 1992 18:06:42 -0500
- Organization: Kansas State University
- Lines: 87
- Message-ID: <1718i2INN2os@matt.ksu.ksu.edu>
- NNTP-Posting-Host: matt.ksu.ksu.edu
- Keywords: Help!
-
- I'm having a problem and it seems there's a simple solution, but I can't
- seem to grasp it right away...here goes:
-
- I've got something like this globally:
-
- TYPE ARecord = Record
- field1 : string[5];
- field2 : string[12];
- field3 : string[17];
- :
- :
- field17: string[7];
- end;
-
- Var Rec : Record;
-
- Now, I need to validate each field, and I've got a bunch of procedures
- to do this that look like this:
-
- Function ValField1(s:string) : Boolean;
- Function ValField2(s:string) : Boolean;
- :
- Function ValField17(s:string): Boolean;
-
- Now, I have to use a 'string' in there because of another place in the
- program that's calling the validation routines...
-
- But what I need to do now is validate ALL the fiellds in a function
- like this:
-
- Function ValidRecord(ARec : ARecord) : Boolean;
-
- I'm trying to call them all, and the best way I could think of was to
- write a function to return the field as a string, based on an index:
-
- Function Field2String(ARec : Record,i : Integer) : String;
- Begin
- Case i of
- 1 : Field2String:=ARec.Field1;
- 2 : Field2String:=ARec.Field2;
- :
- :
- 17 : Field2String:=ARec.Field17;
- Else FatalError('Invalid Index in Field2String');
-
- Now in my ValidRecord() function call, I tried to do something like this:
-
- Function ValidRecord(ARec : ARecord) : Boolean;
- Var Tmp : Boolean; { temporary results }
- Begin
- Tmp := True;
- If Not ValField1(Field2String(ARec,1)) then Tmp:=False
- Else If Not ValField2(Field2String(ARec,2)) then Tmp:=False
- :
- :
- Else If Not ValField17(Field2String(ARec,17)) then Tmp:=False;
- ValidRecord:=Tmp;
- End; { ValidRecord }
-
- My problem: I get Error 122: Invalid variable reference.
-
- Help reveals: This construct follows the syntax of a variable
- reference, but it does not denote a memory
- location. Most likely, you are calling a pointer
- function, but forgetting to dereference the
- result.
-
- Now, why can I call a function like this:
-
- s:=Upper(Copy(x,1,5)); { upcase 1st 5 letters of x }
-
- Copy is a function.
- Upper is a function.
-
- So is Field2String.
- So is ValField.
-
- Why can I call a function with another as an argument in one case but
- not another? *groan*
-
- -- Rich
-
- --
- Rich Holland | INTERNET: holland@matt.ksu.ksu.edu
- 100 Jardine Terr, Apt A7 | BITNET : holland@ksuvm
- Manhattan, KS 66502-3357 | UUCP : ...!rutgers!matt.ksu.ksu.edu!holland
- "Jesus saves...but Gretzky gets the rebound! He shoots! He scores!!"
-