[fpc-pascal] counting items in a set type

Graeme Geldenhuys graemeg.lists at gmail.com
Thu Jan 10 14:58:34 CET 2008


On 10/01/2008, Michael Van Canneyt <michael at freepascal.org> wrote:
> >
> >  for i := Low(TfpgMsgDlgBtn) to High(TfpgMsgDlgBtn) do
> >  begin
> >     if i in Buttons then
> >         inc(counter);
> >  end;
> >
> > Is there a better/quicker way of doing this?
>
> No.
> You can try casting to an integer and count all set bits, but that's
> highly non-portable and will not work for all sets.

[ Wow, a quick response! ]

OK, thanks Michael.  The for loop actually gives me time to extract
the correct string (text) for each enum type at the same time, so it
ends up being handy after all.  I just wasn't sure if there was a
different way to do it.


Regards,
  - Graeme -


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



More information about the fpc-pascal mailing list