Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-02

How to init Array values in a record?

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

yu ping
          _TBBUTTON            = Record
                                 iBitmap      : cint;
                                 idCommand    : cint;
                                 fsState      : BYTE;
                                 fsStyle      : BYTE;
                                 bReserved    : ARRAY[0..1] OF BYTE;
 // padding for alignment=
                                 dwData       : DWORD_PTR;
                                 iString      : INT_PTR;
                                 END;
         TBBUTTON             = _TBBUTTON;
I want to init record values when I define variables like following:

tbrbtns:array[0..5] of TBBUTTON =(

(iBitmap:7;idCommand:10000;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_BUTTON;(0,0);dwData:0;iString:0), ...
);
but the field "bReserved" is a array,I don't know how to init a array field in a record,any one can help?
Thanks

yu ping
to Anthony Walter

I use :
tbrbtns:array[0..5] of TBBUTTON =(

(iBitmap:7;idCommand:10000;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_BUTTON;dwData:0;iString:0),

(iBitmap:8;idCommand:10001;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_BUTTON;dwData:0;iString:0),

(iBitmap:0;idCommand:0;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_SEP;dwData:0;iString:0),

(iBitmap:0;idCommand:10002;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_BUTTON;dwData:0;iString:0),

(iBitmap:1;idCommand:10003;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_BUTTON;dwData:0;iString:0),

(iBitmap:2;idCommand:10004;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_BUTTON;dwData:0;iString:0)
);
 compile success,I don't know why
The org defination is:
         _TBBUTTON            = Record
                                 iBitmap      : cint;
                                 idCommand    : cint;
                                 fsState      : BYTE;
                                 fsStyle      : BYTE;
{$IFDEF _WIN64}
                                 bReserved    : ARRAY[0..5] OF BYTE;
 // padding for alignment
{$ELSE}
{$IFDEF _WIN32}
                                 bReserved    : ARRAY[0..1] OF BYTE;
 // padding for alignment
{$ENDIF}
{$ENDIF}
                                 dwData       : DWORD_PTR;
                                 iString      : INT_PTR;
                                 END;
         TBBUTTON             = _TBBUTTON;

2010/2/5 Anthony Walter

Show quoted text 8 lines
Like so: (iBitmap:0; idCommand: 0; fsState:0; fsStyle:0; bReserved: (0,0); dwData: nil; iString: nil) _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Jonas Maebe
to yu ping
yu ping wrote 16 lines
I use : tbrbtns:array[0..5] of TBBUTTON =( (iBitmap:7;idCommand:10000;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_BUTTON;dwData:0;iString:0), (iBitmap:8;idCommand:10001;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_BUTTON;dwData:0;iString:0), (iBitmap:0;idCommand:0;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_SEP;dwData:0;iString:0), (iBitmap:0;idCommand:10002;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_BUTTON;dwData:0;iString:0), (iBitmap:1;idCommand:10003;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_BUTTON;dwData:0;iString:0), (iBitmap:2;idCommand:10004;fsState:TBSTATE_ENABLED;fsStyle:TBSTYLE_BUTTON;dwData:0;iString:0) ); compile success,I don't know why

Probably because you are using Delphi mode. Delphi allows skipping record fields in typed constant declarations, so FPC in Delphi mode also allows this. FPC will still give a warning in this case though. In other syntax modes, you get an error if you skip fields.

Jonas