Search code examples
arraysvhdlrecord

How to initialize an array of record in VHDL?


I'm initializing an array of record which also contains a string. I'm getting an error HDLCompiler:806 Line 109: Syntax error near "text_passages" (Last line in the code below). What's the correct way of initialization?

type text_info is
    record
        text : string(1 to 15);
        x: integer;
        y: integer;
    end record;
constant init_text_info: text_info := (text => "               ", x => 0, y => 0);
type text_info_array is array(natural range <>) of text_info;

My declaration and initialization is as follows

signal text_passages : text_info_array(0 to 1) := (others => init_text_info);
text_passages(0) <= (text => "This is a Test.", x => 50, y => 50);

Solution

  • Well, you've got an extra bracket at the end of your last line, but apart from that, it's fine. (I doubt the error message you report is caused by that bracket.) The last line should be:

    text_passages(0) <= (text => "This is a Test.", x => 50, y => 50);
    

    An [MCVE]:

    entity E is
    end entity ;
    
    architecture A of E is
    
      type text_info is
        record
            text : string(1 to 15);
            x: integer;
            y: integer;
        end record;
      constant init_text_info: text_info := (text => "               ", x => 0, y => 0);
      type text_info_array is array(natural range <>) of text_info;
      signal text_passages : text_info_array(0 to 1) := (others => init_text_info);
    
    begin
    
      text_passages(0) <= (text => "This is a Test.", x => 50, y => 50);
    
    end architecture A;
    

    https://www.edaplayground.com/x/4ARJ

    (It's always best to submit an MCVE.)