I would like to be able to declare a constant array of fixed length string for a GTK ComboBox. Is it possible to do with two parameters in ADA?
This code allows the size of the array to be set by declaring the strings. Is it possible to replace the constant in the spec with a parameter somehow?
A simple array does not allow a discriminant. A discriminant record does not permit an anonymous array.
Edit:
Can I somehow declare a type equivalent to the form:
type ArrayOfStrings( sringlength : positive; arraysize : positive ) array( 1..arraysize ) of string( 1..stringlength );
This form is not possible because an array can not have a discriminant.
OR
subtype SelectorString is string;
type SelectorStringArray( arraysize : positive; stringlength : positive ) is record stringarray : array( 1..arraysize ) of SelectorString( 1..stringlength ); end record;
This form is not possible because a record can not have anonymous arrays.
Answered:
The following works,
package Selectors.Strings is
subtype ArrayIndex is positive range 1..64; -- maximum entries in ComboBox
subtype TextIndex is positive range 1..32; -- maximum entry length
type SelectorStringArray is array( arrayindex range <>, textindex range <> ) of character;
function StringSelector( stringarray : SelectorStringArray ) return ArrayIndex;
sel : SelectorStringArray := ( "aa", "bb", "cc", "dd" );
end Selectors.Strings;
The strings in sel must all be the same length.
Thanks,
old engineer
package Selectors.Strings is SelectorStringLength : constant := 2; subtype SelectorString is string( 1..SelectorStringLength ); type SelectorStringArray is array( positive range <> ) of SelectorString; subtype SelectorStringIndex is positive; function StringSelector( stringarray : SelectorStringArray ) return SelectorStringIndex; selectarray : SelectorStringArray := ( "aa", "bb", "cc", "dd" ); end Selectors.Strings;
procedurethat takes aSelectorStringArrayparameter and setsselectarray?Adais a computer language,ADAis a professional society for dentists.