So passt es jetzt:
Delphi-Quellcode:
procedure TPrintContacts.PrintAllContacts;
var
i: Integer;
begin
Printer.Title := 'Adressdatenbank - Kontaktliste drucken';
Printer.Orientation := poPortrait;
Printer.BeginDoc;
FCanvas := Printer.Canvas;
SetMapMode(Printer.Canvas.Handle, MM_LOMETRIC);
FPaperWidth := GetDeviceCaps(Printer.Canvas.Handle, HORZSIZE);
FPaperHeight := GetDeviceCaps(Printer.Canvas.Handle, VERTSIZE);
for i := 0 to (FContactList.Count - 1) div CONTACTS_PER_PAGE do
begin
PrintAllContactsHeader;
PrintAllContactsFooter(Printer.PageNumber);
PrintPageContacts(i);
NewPageIfNeeded(i);
end;
Printer.EndDoc;
end;
procedure TPrintContacts.PrintPageContacts(PageIndex: Integer);
var
j: Integer;
begin
for j := 0 to CONTACTS_PER_PAGE - 1 do
begin
if (PageIndex * CONTACTS_PER_PAGE + j) = FContactList.Count - 1 then break;
PrintAllSingleContact(ContactPosition(j), FContactList.Items[PageIndex * CONTACTS_PER_PAGE + j]);
end;
end;
function TPrintContacts.ContactPosition(Index: Integer): Integer;
var
Parts: Integer;
begin
Parts := (FPaperHeight*10 - TOPMARGIN - BOTTOMMARGIN) div CONTACTS_PER_PAGE;
Result := -(Parts * Index) + TOP_FIRST_DETAIL_LINE;
end;
procedure TPrintContacts.NewPageIfNeeded(PageIndex: Integer);
begin
if PageIndex <> (FContactList.Count - 1) div CONTACTS_PER_PAGE then
Printer.NewPage;
end;
Nur fehlt der letzte Datensatz. Die Seite wird erstellt aber der Datensatz fehlt.
(Ich habe es mal etwas in einzelne Routinen zerlegt, dann wird es übersichtlicher.)