Ignore:
Timestamp:
May 7, 2015, 12:34:29 PM (9 years ago)
Author:
healthsevak
Message:

Updating the working copy to CPRS version 28

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/trunk/CPRS-Chart/fReportsPrint.pas

    r830 r1679  
    4444procedure PrintReports(AReports: string; const AReportsTitle: string);
    4545function StringPad(aString: string; aStringCount, aPadCount: integer): String;
     46function DeleteLineBreaks(const S: string): string;
    4647
    4748implementation
     
    115116  ListItem: TListItem;
    116117  aWPFlag: Boolean;
     118  DistanceFromLeft, DistanceRemaining, TotalSpaceAvailable: Integer;
     119  SigText, LineBreak, PageBreak, LeftMask: string;
     120  LinesPerPage, Limit, Z: Integer;
     121  WrappedSig: TStringList;
    117122begin
    118123  aBasket := TStringList.Create;
    119124  aBasket.Clear;
    120   //frmReports.MemText.Clear;
    121125  aHead := '';
    122126  cnt := 2;
    123   //aWPFlag := false;
    124127  for i := 0 to uColumns.Count - 1 do
    125128    begin
     
    145148      FReportText.Lines.Add(aHead);
    146149      FReportText.Lines.Add('-------------------------------------------------------------------------------');
    147       //frmReports.memText.Lines.Add(aHead);
    148       //frmReports.MemText.Lines.Add('-------------------------------------------------------------------------------');
     150      TotalSpaceAvailable := Length(FReportText.Lines[FReportText.Lines.Count - 1]);
    149151    end;
    150152  for i := 0 to frmReports.lvReports.Items.Count - 1 do
     
    171173                    begin
    172174                      FastAssign(TCellObject(RowObjects.ColumnList[j]).Data, aBasket);
     175                      if POS('SIG', piece(uColumns[StrToInt(piece(aCol, ':', 2))], '^', 1)) > 0 then begin
     176                       DistanceFromLeft := Length(aData); //distance from the left side of the page
     177                       DistanceRemaining := TotalSpaceAvailable - DistanceFromLeft; //Distance to end of page
     178                       LinesPerPage := 40;
     179                       Limit := 10; //Arbitrary limit to detrmine if there is enough space to bother with wrapping.
     180                       LineBreak := #13#10;
     181                       PageBreak := '**PAGE BREAK**';
     182                       X := '';
     183                       LeftMask := StringOfChar(' ', DistanceFromLeft);
     184                       //remove any line breaks from the text
     185                       SigText := StringReplace(aBasket.Text, #13#10, '', [rfReplaceAll]);
     186                       if DistanceRemaining < Limit then begin
     187                        DistanceRemaining := TotalSpaceAvailable;
     188                        LeftMask := '';
     189                       end;
     190                       WrappedSig := TStringList.Create;
     191                       try
     192                        WrappedSig.Text := WrapText(SigText, LineBreak + LeftMask, [' '], DistanceRemaining);
     193                        For Z := 0 to WrappedSig.Count - 1 do begin
     194                          Inc(Cnt);
     195                          If Cnt > LinesPerPage then x := x  + PageBreak;
     196                          X := X + WrappedSig.Strings[Z] + LineBreak;
     197                        end;
     198                       finally
     199                        FreeAndNil(WrappedSig);
     200                       end;
     201                       aData := aData + x;
     202                      end else begin
    173203                      for k := 0 to aBasket.Count - 1 do
    174                         begin
    175                           L := StrToIntDef(piece(uColumns[StrToInt(piece(aCol,':',2))],'^',6),15);
    176                           x := StringPad(aBasket[k], L, L+1);
    177                           aData := aData + x;
    178                         end;
     204                      begin
     205                       L := StrToIntDef(piece(uColumns[StrToInt(piece(aCol,':',2))],'^',6),15);
     206                       x := StringPad(aBasket[k], L, L+1);
     207                       aData := aData + x;
     208                      end;
    179209                    end;
    180210                end;
     211            end;
    181212          end;
    182         //frmReports.memText.Lines.Add(aData);
    183213        FReportText.Lines.Add(aData);
    184214        cnt := cnt + 1;
     
    186216          begin
    187217            cnt := 0;
    188             //frmReports.memText.Lines.Add('**PAGE BREAK**');
    189218            FReportText.Lines.Add('**PAGE BREAK**');
    190219          end;
     
    200229                      aWPFlag := true;
    201230                      FastAssign(TCellObject(RowObjects.ColumnList[j]).Data, aBasket);
    202                       //frmReports.MemText.Lines.Add(TCellObject(RowObjects.ColumnList[j]).Name);
    203231                      FReportText.Lines.Add(TCellObject(RowObjects.ColumnList[j]).Name);
    204232                      cnt := cnt + 1;
    205233                      for k := 0 to aBasket.Count - 1 do
    206234                        begin
    207                           //frmReports.memText.Lines.Add('  ' + aBasket[k]);
    208                           FReportText.Lines.Add('  ' + aBasket[k]);
     235                          FReportText.Lines.Add('' + aBasket[k]);
    209236                          cnt := cnt + 1;
    210237                          if cnt > 40 then
    211238                            begin
    212239                              cnt := 0;
    213                               //frmReports.memText.Lines.Add('**PAGE BREAK**');
    214240                              FReportText.Lines.Add('**PAGE BREAK**');
    215241                            end;
     
    220246        if aWPFlag = true then
    221247          begin
    222             //frmReports.MemText.Lines.Add('===============================================================================');
    223248            FReportText.Lines.Add('===============================================================================');
    224249          end;
    225250      end;
    226251  aBasket.Free;
     252end;
     253
     254function DeleteLineBreaks(const S: string): string;
     255var
     256  Source, SourceEnd: PChar;
     257begin
     258  Source := Pointer(S);
     259  SourceEnd := Source + Length(S);
     260  while Source < SourceEnd do
     261  begin
     262    case Source^ of
     263      #10: Source^ := #32;
     264      #13: Source^ := #32;
     265    end;
     266    Inc(Source);
     267  end;
     268  Result := S;
    227269end;
    228270
Note: See TracChangeset for help on using the changeset viewer.