WITH Loop / Statement

WITH Loop / Statement

WITH Statement or loop is used to make record variables easier. 

Record variable is a complex datatype with one variable we can store multiple values like arrays. Each record having different fields and each of these fields can able to store different data types also. These fields are separated by the '.' or dot sign. If a customer record having field named Name then it can be specified like customer.Name

Syntax Of WITH Loop

Suppose we having three fields names name, address and City then it can be specified in the recod named customer as folows

     customer.Name := Txt[1];

     customer.Address := Txt[2];

     customer.City := Txt[3];

We can sort these kind of representation in the system different way so that we can minimise the number of codings that syntax of WITH Loop is as follows

----------------------------------------------------------------------------

           WITH Record Variable DO Statement

----------------------------------------------------------------------------

 By the help of this syntax we can remodify the abow code as following type of codes

=====================================================

                WITH customer DO BEGIN 

                             Name := Txt[1];

                             Address := Txt[2];

                             City := Txt[3];

                  END; 

=====================================================

Once we cross check the abow codes we found that the Record variable is not found with any of the fields. The computer will automatically konow the identification about each fields assigned to the records.

Related Posts with Thumbnails