home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!psgrain!qiclab!leonard
- From: leonard@qiclab.scn.rain.com (Leonard Erickson)
- Subject: Re: Records and strings
- Message-ID: <1992Aug29.131121.15383@qiclab.scn.rain.com>
- Keywords: Help!
- Reply-To: 70465.203@compuserve.com
- Organization: SCN Research/Qic Laboratories of Tigard, Oregon.
- References: <1718i2INN2os@matt.ksu.ksu.edu> <1992Aug24.033429.15678@qiclab.scn.rain.com> <1992Aug24.065339.19207@kth.se>
- Date: Sat, 29 Aug 1992 13:11:21 GMT
- Lines: 56
-
- kjell@elixir.e.kth.se (Kjell Rilbe) writes:
-
- >In article <1992Aug24.033429.15678@qiclab.scn.rain.com> 70465.203@compuserve.com writes:
- >>>
- >>>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 }
- >>
- >>Well, why not do it *this* way?
- >>
- >>Function ValidRecord(Arec : Arecord) : Boolean;
- >>var tmp : boolean;
- >>begin
- >> Btmp:=true;
- >> tmp:=tmp and Valfield1(Arec.field1);
- >> tmp:=tmp and ValField2(Arec.field2);
- >> ....
- >> tmp:=tmp and Valfield17(Arec.field17);
- >> ValidRecord := tmp
- >>end;
- >>
- >>I can't figure out why you even bothered with that other stuff.
- >>Also note the much cleaner direct boolean assignment.
- >>--
- >>Leonard Erickson leonard@qiclab.scn.rain.com
-
- >Well, at least there's one good reason to do it the way Rich does.
- >It will execute faster, since in most cases only a few of the
- >ValField* functions will be called.
-
- So do it *this* way:
-
- {$B-}
- if ValidField(1,Arec) and ValidField(2,Arec) and ...
- ... and Validfield(17,Arec)
- then
- ValidRecord :=True
- else
- ValidRecord := False;
- {B+}
-
- That'll do it fast *and* be readable!
- --
- Leonard Erickson leonard@qiclab.scn.rain.com
- CIS: [70465,203] 70465.203@compuserve.com
- FIDO: 1:105/51 Leonard.Erickson@f51.n105.z1.fidonet.org
- (The CIS & Fido addresses are preferred)
-