home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / pascal / 5102 < prev    next >
Encoding:
Text File  |  1992-08-29  |  2.1 KB  |  69 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!psgrain!qiclab!leonard
  3. From: leonard@qiclab.scn.rain.com (Leonard Erickson)
  4. Subject: Re: Records and strings
  5. Message-ID: <1992Aug29.131121.15383@qiclab.scn.rain.com>
  6. Keywords: Help!
  7. Reply-To: 70465.203@compuserve.com
  8. Organization: SCN Research/Qic Laboratories of Tigard, Oregon.
  9. References: <1718i2INN2os@matt.ksu.ksu.edu> <1992Aug24.033429.15678@qiclab.scn.rain.com> <1992Aug24.065339.19207@kth.se>
  10. Date: Sat, 29 Aug 1992 13:11:21 GMT
  11. Lines: 56
  12.  
  13. kjell@elixir.e.kth.se (Kjell Rilbe) writes:
  14.  
  15. >In article <1992Aug24.033429.15678@qiclab.scn.rain.com> 70465.203@compuserve.com writes:
  16. >>>
  17. >>>Now in my ValidRecord() function call, I tried to do something like this:
  18. >>>
  19. >>>Function ValidRecord(ARec : ARecord) : Boolean;
  20. >>>Var Tmp : Boolean;  { temporary results }
  21. >>>Begin
  22. >>>  Tmp := True;
  23. >>>  If Not ValField1(Field2String(ARec,1)) then Tmp:=False
  24. >>>  Else If Not ValField2(Field2String(ARec,2)) then Tmp:=False
  25. >>>  : 
  26. >>>  Else If Not ValField17(Field2String(ARec,17)) then Tmp:=False;
  27. >>>  ValidRecord:=Tmp;
  28. >>>End; { ValidRecord }
  29. >>
  30. >>Well, why not do it *this* way?
  31. >>
  32. >>Function ValidRecord(Arec : Arecord) : Boolean;
  33. >>var tmp : boolean;
  34. >>begin
  35. >>    Btmp:=true;
  36. >>    tmp:=tmp and Valfield1(Arec.field1);
  37. >>    tmp:=tmp and ValField2(Arec.field2);
  38. >>    ....
  39. >>    tmp:=tmp and Valfield17(Arec.field17);
  40. >>        ValidRecord := tmp
  41. >>end;
  42. >>
  43. >>I can't figure out why you even bothered with that other stuff.
  44. >>Also note the much cleaner direct boolean assignment. 
  45. >>-- 
  46. >>Leonard Erickson              leonard@qiclab.scn.rain.com
  47.  
  48. >Well, at least there's one good reason to do it the way Rich does.
  49. >It will execute faster, since in most cases only a few of the
  50. >ValField* functions will be called.
  51.  
  52. So do it *this* way:
  53.  
  54. {$B-}
  55. if ValidField(1,Arec) and ValidField(2,Arec) and ...
  56.    ... and Validfield(17,Arec) 
  57. then
  58.   ValidRecord :=True
  59. else
  60.   ValidRecord := False;
  61. {B+}
  62.  
  63. That'll do it fast *and* be readable!
  64. -- 
  65. Leonard Erickson              leonard@qiclab.scn.rain.com
  66. CIS: [70465,203]             70465.203@compuserve.com
  67. FIDO:   1:105/51     Leonard.Erickson@f51.n105.z1.fidonet.org
  68. (The CIS & Fido addresses are preferred)
  69.