Release 10.1A: OpenEdge Development:
Progress 4GL Handbook

> ## Using a buffer handle and buffer field handles

> In the next chapter, you’ll learn how to define dynamic data management objects such as buffers, and queries. In the meantime, it is useful to know that these objects, whether static or dynamic, have handles and attributes just like any other Progress object.

> | To see how to use buffer handle and buffer field handles:

> 1. Create a new internal procedure called initSelection.

> 2. Begin the internal procedure with these definitions:

>     /*---------------------------------------------------------------------
>       Purpose:     Set the selection list to a list of all the fields in the
>                    OrderLine table.
>       Parameters:  <none>
>     ---------------------------------------------------------------------*/
>     DEFINE VARIABLE hBuffer AS HANDLE      NO-UNDO.
>     DEFINE VARIABLE iField  AS INTEGER     NO-UNDO.

> To build a list of all the fields in the OrderLine table at run time, you need to be able to walk through a list of those fields in the OrderLine record buffer.

> 3. To do this, you first need to use the `HANDLE` attribute to get the buffer handle:

>     hBuffer = BUFFER OrderLine:HANDLE.

> Notice that you need to include the `BUFFER` keyword in the statement so that Progress knows how to identify the literal value OrderLine.

> Next, you need to know that the buffer object has an attribute called `NUM-FIELDS` that conveniently tells you how many fields there are in the buffer.

> 4. Use this code to start a block that walks through all those fields:

>     DO iField = 1 TO hBuffer:NUM-FIELDS:

> There is another Progress object that represents a single field in a buffer. You get the handle of a particular field object using the buffer’s `BUFFER-FIELD` attribute. `BUFFER-FIELD` takes a single argument, which can be either the sequential field position within the buffer or the field name.

> 5. In this procedure, since you just want to walk through all the fields to build up a list, use its position to identify it:

>     hBuffer:BUFFER-FIELD(iField)

> 6. Finally, you need to know that, like other objects, the `BUFFER-FIELD` has various attributes you can query or set. In this case you want the `NAME` attribute. The Progress 4GL (beginning in Progress Version 9.1D) lets you chain multiple colon-separated references together in a single expression, such as this:

>     hBuffer:BUFFER-FIELD(iField):NAME

> The only requirement is that each of the elements in the expression until the last one must be a handle, since each element is in turn an attribute of the handle that the expression yields at that point in its evaluation. Thus the expression above represents this sequence:

> Starting with the handle to the buffer, retrieve the handle of the buffer field that is in position `iField`. Then retrieve the `NAME` attribute of that field handle.

> You could even leave out the earlier step of saving off the buffer handle in a variable and put that into the expression as well, as in:

>     BUFFER OrderLine:BUFFER-FIELD(iField):NAME

> In this example, you did not to do this because the buffer handle is referenced in several different statements in this little procedure, so it’s more efficient and makes the code a bit more readable to save the value off once and reuse it.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095