Dear friends,
It turns out I have been too optimistic.
I had two thoughts:
1) I can unpack/repack the structures and work on them. FALSE! Here I have records, not arrays!
2) I cannot assign the array of chars in a single instruction, but I can assign a single char: all I need is a loop. FALSE! My situation is in effects more problematic, probably because also some of the sub-structures are packed... See below
These are the declarations I have (stripped down)
TYPE
ITEN = packed RECORD KEY :PACKED ARRAY [1..MAX] OF CHAR; PUNT:integer; END;
ND = packed RECORD POS : integer; IDX : packed ARRAY [1..ONDM2] OF ITEN; END;
VAR DATA : ND;
This assignment fails:
DATA.IDX[H1].KEY:= <array of char>;
I thought I could loop through this assignment: DATA.IDX[H1].KEY[x] := <char>; But it still fails. The compiler says: Error: cannot take address of packed record field `IDX'
BUT if the problem is with IDX, why this assignment is ok??? DATA.IDX[H1].PUNT := <integer>;
At the moment, the workaround I have found is:
VAR DATA : ND; TMP : ITEN;
TMP:=DATA.IDX[H1]; TMP.KEY:=<array of char>; DATA.IDX[H1]:=TMP;
I cannot really understand why (and if) this should be safer (from the compiler's poin of view) than doing DATA.IDX[H1].KEY:= <array of char>;
Any thought? Ciao Francesco Bonomi
Francesco Bonomi Si.lab s.r.l. Via Citille 13 50022 Greve in Chianti FI- Italy
Tel +39 - 055 8544805 Fax +39 - 055 8547418
http//:www.silab.it
On Wed, 4 Feb 2004, Francesco Bonomi wrote:
These are the declarations I have (stripped down)
TYPE
ITEN = packed RECORD KEY :PACKED ARRAY [1..MAX] OF CHAR; PUNT:integer; END;
ND = packed RECORD POS : integer; IDX : packed ARRAY [1..ONDM2] OF ITEN; END;
VAR DATA : ND;
I see two problems: 1. "packed array [ ] of char" is not a string. there are operations you can use with strings that don't work on a packed array. 2. "packed record". Most cpu's handle data on four byte boundrys. The compiler "knows" this so if a data item is not a multiple of 4 bytes and it is not a packed record the item gets padded to fit. While you can create software to handle data items that don't start on a 4 byte boundry, memory and storage is so cheap these days you really wouldn't want to.
If it were me I would: change "array[ ] of char" to a string drop the use of "packed" write a separate program to do a one time conversion of all your old data to the new format.
Hope this helps, Russ