Problem with record structures

Beta Testing discussion on mikroPascal for dsPIC30/33 and PIC24.
Post Reply
Author
Message
anton
Posts: 807
Joined: 23 Sep 2004 09:16
Location: South-Africa
Contact:

Problem with record structures

#1 Post by anton » 19 Jun 2009 07:18

Hi,

When creating a record structure and the total size of the record structure is not even, the PIC crashes when you try to access a variable in the record.

For example the following code works.

Code: Select all

type
  TELinkInfo    = record
    IPAddr      : String[17];
    SubMask     : String[17];
    Gateway     : String[17];
    HostIP1     : String[17];
    HostIP2     : String[17];
    ConInterval : word;
    CommTimeout : word;
    Version     : String[7];
  end;

type
  TComPortInfo  = record
    MeterMake   : word;
    BaudRate    : word;
    Parity      : word;
    TCPPort     : word;
    Connected   : word;
    SNumber     : String[17];
  end;

var
  ELinkInfo     : TELinkInfo;
  ComPortInfo   : array[0..3] of TComPortInfo;

begin
  ComPortInfo[1].TCPPort := 1234;
end;
But when I change one of the variables to for example SNumber to be uneven, the PIC would crash.

Code: Select all

type
  TComPortInfo  = record
    MeterMake   : word;
    BaudRate    : word;
    Parity      : word;
    TCPPort     : word;
    Connected   : word;
    SNumber     : String[16];
  end;
The same would happen when you change one of the words to a byte.

Thank you
Anton
Another proud user of LV 24-33A Development System and mikroPascal PRO for dsPIC :)
PortA not working? Add CMCON := 7; PortD not working? Add ADCON1 := 6;
To paste code on the forum, please use the [b] Code [/b] button !! ;)

Post Reply

Return to “mikroPascal for dsPIC30/33 and PIC24 Beta Testing”