[fpc-pascal] counting items in a set type

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Jan 10 14:44:41 CET 2008


Hi,

I momentarily forgot how to do this... It's late in the week. ;)

I have set items in a Set type.  How to I count how many items are in the set?

eg:

TfpgMsgDlgBtn = (mbNoButton, mbYes, mbNo, mbOK, mbCancel, mbAbort,
   mbRetry, mbIgnore, mbAll, mbNoToAll, mbYesToAll, mbHelp, mbClose);
TfpgMsgDlgButtons = set of TfpgMsgDlgBtn;

....

var
  Buttons: TfpgMsgDlgButtons;

....

  Buttons := [mbRetry, mbIgnore];   // it can be any amount of items.


How do I know how many items are in Buttons?

Yes I can do a....

 for i := Low(TfpgMsgDlgBtn) to High(TfpgMsgDlgBtn) do
 begin
    if i in Buttons then
        int(counter);
 end;

Is there a better/quicker way of doing this?


Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list