How to init Array values in a record?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to init Array values in a record?

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




_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to init Array values in a record?

Anthony Walter-3
Like so:

(iBitmap:0; idCommand: 0; fsState:0; fsStyle:0; bReserved: (0,0);
dwData: nil; iString: nil)
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to init Array values in a record?

yu ping
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 <[hidden email]>
Like so:

(iBitmap:0; idCommand: 0; fsState:0; fsStyle:0; bReserved: (0,0);
dwData: nil; iString: nil)
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal



--
http://pingyu.wordpress.com.cn
http://step7.blog.163.com/  

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to init Array values in a record?

Jonas Maebe-2

On 04 Feb 2010, at 17:32, yu ping wrote:

> 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_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal