` Printed Icetips Article

Icetips Article



Par2: Where, What
2001-07-31 -- Dennis Evans
 
.

  Where:  is a function that returns the sequence number of a field inside a
structure. (fiel record, group or a queue) The sequence number is the number
of the field in order it was declared.

MyGroup  group
F_One   type
F_two    type
F_three  type
    end

x = where(MyGroup, F_Two)  x will equal two.

What returns a reference to a field.  An ANY type.

X &= what(MyGroup, where(MyGroup, F_Two))
X is now a reference to MyGroup.F_Two
What you do to F_Two is reflected in X and what you do to X is reflected in
F_Two.

Think of an ANY type as a pointer, technically it is not because there is
some other stuff in the back ground but you and I seldom if ever need to be
concerned.

When the compiler creates an ANY it reserves some space some where in
memory,
part of the space is an address that the ANY type uses to point to other
variables.    In the example above the field F_Two was allocated a location
in memory by the compiler, exactly where does not matter the compiler knows.
When the
X &= what(... is done the address part of the ANY variable is filled with
the same address as the field F_Two.   Now when you do
X = 'Welcome to Clarion' the compiler knows this is an assignment and places
the string at the location pointed to by the address in the ANY variable,
which is the same location as the F_two field.
You can also do comparisons

   F_Two = 'Some Value'
   if (X = 'Some Value')
      do this
   end
  the IF statement will evaluate to true, the compiler does the comparison
on the location in memory pointed to by the ANY variable, in this case X.

The advantage is that I can write procedures to process files, queues and
other structures and never touch the structure.

if I want the fields in a browse queue,

  loop x = 1 to 10
    MyAny &= what(BrwX.Q, x)
    if (MyAny = 1000)
       do something with MyAny
    end
  end

  I can now process all the fields in a queue.

As far as reading the doc's cover the ANY type fairly well and the
ABC source files use the others in a several locations.
Look at how the keys are assigned to the queue used by the FileManager to
track key info,  the WindowManager History stuff is another decent example.
They are all over the source files.



Printed May 6, 2024, 10:25 am
This article has been viewed/printed 35116 times.