title: How can I extract elements from a record using an integer reference in VHDL?
body: <p>Firstly here is what I'm aiming to do, using made-up VHDL syntax...</p>
  
  <pre><code>type type_johns_record is
    first_element : std_logic;
    second_element: std_logic_vector(3 downto 0);
    third_element : boolean;
  end record;
  ....
  ....
  
  for ii in johns_record'range loop
    if johns_record.type_johns_record'val(ii) = .... then
      exit;
    end if;
  end loop;
  </code></pre>
  
  <p>Hopefully you can see that I'm trying to reference the elements of a record using similar syntax to that which can be used to reference an enumerated type.  This however (of course) does not work.  Is there a similar syntax that will work?  My solution at the moment is to use a record_info field and work using std_logic_vectors as shown below....</p>
  
  <pre><code>type type_johns_record is record
      first_element : std_logic;
      second_element : std_logic_vector(3 downto 0);
      third_element : boolean;
      record_info : type_integer_array(2 downto 0);
    end record;
  
    function type_johns_record2slv(d : type_johns_record) return std_logic_vector is
    begin
      return (d.first_element &amp; d.second_element &amp; bool2sl(d.third_element));
    end function;
  
    constant johns_record_zero : type_johns_record := (first_element =&gt; '0',
                                                       second_element =&gt; "0000",
                                                       third_element =&gt; false,
                                                       record_info =&gt; (1, 4, 1));
  
    -- can be used with any type for which a record_info is known
    function get_record_element(input : std_logic_vector; element_number : integer; record_info :     type_integer_array) return std_logic_vector is
      variable r : type_slv32_array(record_info'length-1 downto 0);
      variable pos : integer := 0;
    begin
      for ii in record_info'range loop
        r(ii)(record_info(ii)-1 downto 0) := input(pos+record_info(ii)-1 downto pos);      
      end loop;
      return r(element_number)(record_info(element_number)-1 downto 0);
    end function;
  </code></pre>
  
  <p>I can then use these functions (which are in a package) as follows...</p>
  
  <pre><code> for ii in johns_record.record_info'range loop
     if get_record_element(type_johns_record2slv(johns_record), ii, johns_record.record_info) = conv_std_logic_vector(4, johns_record.record_info(ii)) then
        exit;
     end if;
   end loop;    
  </code></pre>
  
  <p>This really sucks and specifying the record_info is error prone and only marginally less time consuming that writing out individual element comparisons line by line.  Please offer a better solution!!!  </p>