use DateUtils

function DaysInMonth(aDay, aMonth, aYear: Word): Integer;

var I: Integer;

Dt: TDateTime;

begin

Result := 0;

Dt := EncodeDate(aYear, aMonth, 1);

for I := 0 to DaysInMonth(Dt)-1 do

if DayOfWeek(Dt + I) = aDay then

Result := Result + 1;

end;

use like

NumSundays := DaysInMonth(7, 7, 2009); // = 4