The code of the main program:
Code: Select all
program Externals_test;
uses TestExtUnit;
begin
Test;
end.
Code: Select all
unit TestExtUnit;
const UsbManufacturer : string[20]; external;
UsbProduct : string[20]; external;
UsbSerialNo : string[20]; external;
VENDOR_ID : word; external;
PRODUCT_ID : word; external;
DEVICE_REL_NR : word; external;
var Ptr: ^const byte;
Wrd: word;
procedure Test;
implementation
const Table1: array[3] of word = // <------------ content of the table is all zeroes
(
(VENDOR_ID),
(PRODUCT_ID),
(DEVICE_REL_NR)
);
Table2: array[5] of word = (1,2,3,4,5);
Table3: array[5] of word = // <------------ content of the table is all zeroes
(
(VENDOR_ID),
(PRODUCT_ID),
(DEVICE_REL_NR)
);
Table4: array[5] of word = (1,2,3,4,5);
procedure Test;
begin
Ptr := @UsbManufacturer;
Wrd := @UsbProduct;
Wrd := Vendor_ID; // <------------ OK
Wrd := Product_id; // <------------- Ok
Wrd := DEVICE_REL_NR; // <------------- Ok
Ptr := @Table1;
Ptr := @Table2;
Ptr := @Table3;
Ptr := @Table4;
end;
end.
Code: Select all
Unit USB_HID_ProjectItems;
const
UsbManufacturer : string[20] = 'Me and myself';
UsbProduct : string[20] = 'My Product';
UsbSerialNo : string[20] = '077';
VENDOR_ID : word = $1234;
PRODUCT_ID : word = $23;
DEVICE_REL_NR : word = 0101;
implementation
end.
Now the problem:
- The tables 1 and 3 are filled with all zeroes (not the constant value I expected):
Code: Select all
;TestExtUnit.mpas,21 :: TestExtUnit_Table1
0x00D4 0x0000 ;TestExtUnit_Table1+0
0x00D6 0x0000 ;TestExtUnit_Table1+2
0x00D8 0x0000 ;TestExtUnit_Table1+4
So, apparently there is a problem when using external constants as values in a constant table. If the constants are not declared as "external", but unit "USB_HID_ProjectItems" is put in the "uses" clause of "TestExtUnit" then also the values in the tables are Ok.
Thanks in advance!