Skip to main content

CountParts

procedure CountParts;

Example

procedure Recount(const Parts: TIdMessageParts; var Value: Variant);
begin
Parts.CountParts;
Value := Parts.TextPartCount + Parts.AttachmentCount;
end;

Usage

CountParts resets and recomputes cached text, attachment and hidden related-part counts from current current classifications and Content-ID values.

Additional Technical Info

CountParts resets all three native counters to zero, then scans every current item. A nonempty ContentID increments the hidden related count. Virtual PartType increments either TextPartCount or AttachmentCount.

The cached values are not maintained automatically, so call after every structural/metadata change when fresh counts matter. The sum of exposed counts equals scanned Count for the current two-value enumeration on normal completion; related parts overlap rather than form a third category.

Recount is non-transactional: counters are cleared before scanning. An invalid item, virtual dispatch/header exception or concurrent mutation can leave partial values. Time is O(Count), and the collection is not thread-safe.

The source-reviewed example consumes values only after the refresh and was not executed.

External references

Created 2026-07-15