How To…Align Memo Bottoms

Question

“How can I align the bottoms of two stretching memos?”

Solution

This example contains a report with two stretching Memos inside a Region. Region.KeepTogether is set to True.

The Memo OnDrawCommandCreate event is used to obtain a reference to the DrawCommand object that is created each time the object generates on the page. The Detail AfterPrint event is used to compare and adjust the positions of the Memo DrawCommands.

Download: AlignMemoBottoms.zip

Sample Delphi code:

{------------------------------------------------------------------------------}
{ TForm1.ppDBMemo1DrawCommandCreate }

procedure TForm1.ppDBMemo1DrawCommandCreate(Sender, aDrawCommand: TObject);
begin
  FDBMemo1DrawCmd := TppDrawCommand(aDrawCommand);

end;

{------------------------------------------------------------------------------}
{ TForm1.ppMemo1DrawCommandCreate }

procedure TForm1.ppMemo1DrawCommandCreate(Sender, aDrawCommand: TObject);
begin
  FMemo1DrawCmd := TppDrawCommand(aDrawCommand);

end;

{------------------------------------------------------------------------------}
{ TForm1.ppDetailBand1AfterPrint }

procedure TForm1.ppDetailBand1AfterPrint(Sender: TObject);
begin

  // align bottoms
  if FDBMemo1DrawCmd.Height > FMemo1DrawCmd.Height then
    FMemo1DrawCmd.Top := (FDBMemo1DrawCmd.Top + FDBMemo1DrawCmd.Height) - FMemo1DrawCmd.Height
  else
    FDBMemo1DrawCmd.Top := (FMemo1DrawCmd.Top + FMemo1DrawCmd.Height) - FDBMemo1DrawCmd.Height;

end;