print a selected part of a memo by QuickReport

General TRichView support forum. Please post your questions here
Post Reply
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

print a selected part of a memo by QuickReport

Post by j&b »

Hello,

I want to print a selected part of a memo by QuickReport (look at "DuenneTabLinien(an/aus)").
All runs fine until I have put a table into the memo. Now the whole memo is shown in the quickReport.preview.
What's to do ?

Code: Select all

procedure TForm1.MemoDruckenClick(Sender: TObject);
var MemoText: TMemoryStream;
      colorMode: integer;
begin
 //colorMode aus INI-Datei  
try
  fQr:= TfQr.Create(Application);
  with fQr do begin
      [color=red][b]DuenneTabLinien('an');  [/b][/color]  <---   this procedure is the reason
      MemoText := TMemoryStream.Create;      
      if Memo.SelectionExists=true then Memo.SaveRVFToStream(MemoText, True)
      else Memo.SaveRVFToStream(MemoText, False);
      [color=red][b]DuenneTabLinien('aus');   [/b][/color]   <----- 
      MemoText.Position := 0;
      memo.Deselect; 
      memo.Format;
      rpt.height:= 1175;
      QRRichView1.width:= memo.width; 
      case ColorMode of
        0 : QRRichView1.ColorMode := rvcmColor;
        1 : QRRichView1.ColorMode := rvcmPrinterColor;
        2 : QRRichView1.ColorMode := rvcmGrayScale;
        3 : QRRichView1.ColorMode := rvcmBlackAndWhite;
        4 : QRRichView1.ColorMode := rvcmBlackOnWhite;
      end;
      QRRichView1.LoadRVFStream(MemoText);
      Rpt.preview;
  end; // of fQr  
finally
  fQR.release;
  MemoText.Free; 
  Screen.Cursor :=crDefault; 
  lockWindowUpdate(0);
end;
end;   //of rpt_QuickReport

procedure TForm1.[color=red][b]DuenneTabLinien[/b][/color](const an_aus: string);
var anzTab,j,itemNo,data: integer;
begin
  //exit;  //zu Testzwecken übersprungen
  try
    if an_aus='an' then lockWindowUpdate(Form1.handle); 
    anzTab:=0;
    for j := 0 to Memo.ItemCount-1 do 
    if Memo.GetItemStyle(j)=rvsTable then inc(anzTab);
    if anzTab>0 then begin
      for j := 1 to anzTab do begin 
        storedRveTabNo:=j; 
        setRveTabNo;
        if (not memo.CanChange) then break;
        try  
          ItemNo := rveTable.GetMyItemNo; 
          memo.BeginUndoGroup(rvutModifyItem);  
          memo.SetUndoGroupMode(True);    
          memo.BeginItemModify(ItemNo, Data); 
          if an_aus='an' then begin
            rvetable.CellHSpacing:= -2; rvetable.CellVSpacing:= -2;
          end else begin
            rvetable.CellHSpacing:= -1; rvetable.CellVSpacing:= -1;
          end;  
        finally  
          memo.EndItemModify(ItemNo, Data); 
          memo.SetUndoGroupMode(False); 
          memo.Change;
          if query1.state in [dsEdit, dsInsert] then query1.post;
        end;  
      end;
    end;
  finally
    if an_aus='aus' then lockWindowUpdate(0);
  end;  
end;
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I believe it is because saving to database causes reloading (because the document is reloaded if the database content is changed), and the selection is lost. You can save the selection before and restore it after calling DuenneTabLinien.
j&b
Posts: 184
Joined: Mon Sep 05, 2005 1:35 pm

Re: print a selected part of a memo by QuickReport

Post by j&b »

Yes, it seems as if you are right (again).


Instead of

try
fQr:= TfQr.Create(Application);
with fQr do begin
DuenneTabLinien('an'); <--- this procedure is the reason
MemoText := TMemoryStream.Create;
if Memo.SelectionExists=true then Memo.SaveRVFToStream(MemoText, True)
else Memo.SaveRVFToStream(MemoText, False);
DuenneTabLinien('aus'); <-----
MemoText.Position := 0;
memo.Deselect;
memo.Format;
rpt.height:= 1175;


I have written

try
fQr:= TfQr.Create(Application);
MemoText := TMemoryStream.Create; //hier platziert wg. finally

memo.GetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs, true);
DuenneTabLinien('an');
memo.SetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs);


if Memo.SelectionExists=true then Memo.SaveRVFToStream(MemoText, True)
else Memo.SaveRVFToStream(MemoText, False);
DuenneTabLinien('aus');

MemoText.Position:= 0; memo.Deselect; memo.Format;

with fQr do begin
rpt.height:= 1175;
Post Reply