trichview.com

trichview.support




Re: Printing/Preview question


Return to index


Author

Message

William Whitaker

Posted: 01/08/2003 5:03:19


The records do exist in the table. I can view them just fine in a dbrichview

field. However, I am not able to print/preview. Here's the code that I use

to preview/print:


procedure TfmRepCrit.UpdatePreview;


  procedure SearchAndInsertIcon(const Code: String; ImageIndex: Integer);

   begin

    rve1.SetSelectionBounds(0, rve1.GetOffsBeforeItem(0), 0, rve1.GetOffsBeforeItem(0));

    while rve1.SearchText(Code, [rvseoDown]) do

     case ImageIndex of

      0: case pID of

          0: rve1.InsertText((fmMain.ActiveMDIChild as TfmAD).qryAD.fieldbyname('AD').asstring);

          1: rve1.InsertText((fmMain.ActiveMDIChild as TfmTextSearch).RTFMatchTable.FieldByName('AD').asstring);

          2: rve1.InsertText(fmRepCrit2A.qryAD.FieldByName('AD').asstring);

         end;

      1: case pID of

          0: rve1.InsertText((fmMain.ActiveMDIChild as TfmAD).qryAD.fieldbyname('Rev').asstring);

          1: rve1.InsertText((fmMain.ActiveMDIChild as TfmTextSearch).RTFMatchTable.FieldByName('Rev').asstring);

          2: rve1.InsertText(fmRepCrit2A.qryAD.FieldByName('Rev').asstring);

         end;   //          0: rve1.InsertText(src.fieldbyname('Rev').asstring);

      2: case pID of

          0: rve1.InsertText((fmMain.ActiveMDIChild as TfmAD).qryAD.fieldbyname('Description').asstring);

          1: rve1.InsertText((fmMain.ActiveMDIChild as TfmTextSearch).RTFMatchTable.FieldByName('Description').asstring);

          2: rve1.InsertText(fmRepCrit2A.qryAD.FieldByName('Description').asstring);

         end;   //          0: rve1.InsertText(src.fieldbyname('Description').asstring);

      3: case pID of

          0: rve1.InsertText(FormatDateTime('dd MMM yyyy',(fmMain.ActiveMDIChild

as TfmAD).qryAD.fieldbyname('EffDate').asdatetime));

          1: rve1.InsertText(FormatDateTime('dd MMM yyyy',(fmMain.ActiveMDIChild

as TfmTextSearch).RTFMatchTable.FieldByName('EffDate').asdatetime));

          2: rve1.InsertText(FormatDateTime('dd MMM yyyy',fmRepCrit2A.qryAD.FieldByName('EffDate').asdatetime));

         end;   //       3: rve1.InsertText(FormatDateTime('dd MMM yyyy',src.fieldbyname('EffDate').asdatetime));

      4: case pID of

          0: rve1.InsertText((fmMain.ActiveMDIChild as TfmAD).qryAD.fieldbyname('Supercedes').asstring);

          1: rve1.InsertText((fmMain.ActiveMDIChild as TfmTextSearch).RTFMatchTable.FieldByName('Supercedes').asstring);

          2: rve1.InsertText(fmRepCrit2A.qryAD.FieldByName('Supercedes').asstring);

         end;   //       4: rve1.InsertText(src.fieldbyname('Supercedes').asstring);

      5: If pAE = 'X' then

           case pID of

            0: rve1.InsertText((fmMain.ActiveMDIChild as TfmAD).qryAD.fieldbyname('SeriesDesc').asstring);

            1: rve1.InsertText((fmMain.ActiveMDIChild as TfmTextSearch).RTFMatchTable.FieldByName('SeriesDesc').asstring);

            2: rve1.InsertText(fmRepCrit2A.qryAD.FieldByName('SeriesDesc').asstring);

           end   //   rve1.InsertText(src.fieldbyname('SeriesDesc').asstring)

         else

          rve1.InsertText('');

      6: if cbIncludeNotes.checked then

           case pID of

            0: rve1.InsertText((fmMain.ActiveMDIChild as TfmAD).dbNotes.fieldbyname('Notes').asstring);

            1: rve1.InsertText('');

            2: rve1.InsertText(fmRepCrit2A.dbNotes.FieldByName('Notes').asstring);

           end   //   rve1.InsertText(src.fieldbyname('Notes').asstring)

         else

          rve1.InsertText('');

      7: if pID <> 1 then

          case pAE[1] of // series caption

           'A','R' : rve1.InsertText('');

           'P','E' : rve1.InsertText('');

           'X' : rve1.InsertText('Manufacturer:');

          end

         else

          rve1.InsertText('');

      9: if pGrp <> 1 then

          rve1.InsertText('');

     10: case pAE[1] of

          'A','R' : rve1.InsertText(pMfgName);

          'P','E' : rve1.InsertText(pMfgName);

          'X' : rve1.InsertText(pMfgName);

         end;

     end;

   end;


begin

   rve1.LoadRVF(g_dataQADdir+'ADTemplate.rvf');

   rve1.RVFParaStylesReadMode := rvf_sIgnore;

   rve1.RVFTextStylesReadMode := rvf_sIgnore;

   ReplaceFields(rve1.RVData);

   rve1.Format;


   LockWindowUpdate(rve1.Handle);

   try

    SearchAndInsertIcon('#AD#', 0);

    SearchAndInsertIcon('#ACTYPE#', 10);

    SearchAndInsertIcon('#REV#', 1);

    SearchAndInsertIcon('#DESCRIPTION#', 2);

    SearchAndInsertIcon('#EFFDATE#', 3);

    SearchAndInsertIcon('#SUPERCEDES#', 4);

    SearchAndInsertIcon('#SERIES#', 5);

    SearchAndInsertIcon('#LBLSERIES#', 7);

    SearchAndInsertIcon('#NOTES#', 6);

   finally

    LockWindowUpdate(0);

   end;

end;


procedure TfmRepCrit.FormCreate(Sender: TObject);

begin

   InUse := False;

end;


procedure TfmRepCrit.ReplaceFields(RVData: TCustomRVFormattedData);

var i,j: Integer;

    Stream: TMemoryStream;

    Dummy1: TColor;

    Dummy2, Dummy3: Pointer;

    ParaNo: Integer;

    BR, ContinuePara: Boolean;

    table: TRVTableItemInfo;

    r,c: Integer;

begin

  Dummy1 := clNone;

  Dummy2 := nil;

  Dummy3 := nil;

  for i := RVData.Items.Count-1 downto 0 do

    case RVData.GetItemStyle(i) of

      1: // the first text style is used for fields

        begin

          // storing parameters of deleted items

          ParaNo := RVData.GetItemPara(i);

          BR     := RVData.GetItem(i).BR;

          ContinuePara := RVData.GetItem(i).SameAsPrev;

          // loading field value in the stream

          Stream := LoadData(RVData.Items[i]);

          if Stream<>nil then begin

            // deleting the field code

            RVData.DeleteItems(i,1); // in older versions, it was called

DeleteLines

            // inserting the field value

            RVData.InsertRVFFromStream(Stream, i, Dummy1, Dummy2, Dummy3,

False);

            // applying stored parameters to the inserted items

            for j := i to RVData.Items.Count-1 do begin

              if (i=j) then begin

                RVData.GetItem(j).SameAsPrev := ContinuePara;

                if BR then

                  RVData.GetItem(j).BR := True;

              end;

              if (j>i) and RVData.IsParaStart(j) then

                break;

              RVData.GetItem(j).ParaNo := ParaNo;

            end;

            Stream.Free;

          end;

        end;

      rvsTable:

        begin

          // recursive call for table cells

          table := TRVTableItemInfo(RVData.GetItem(i));

          for r := 0 to table.Rows.Count-1 do

            for c := 0 to table.Rows[r].Count-1 do

              if table.Cells[r,c]<>nil then

                ReplaceFields(table.Cells[r,c]);

        end;

    end;

  RVData.Normalize;

end;


// Loading field code

function TfmRepCrit.LoadData(const Code: String): TMemoryStream;

begin

  Result := nil;

//  if not fmAD.qryAD.Locate('AD', Code, []) then

//    exit;

  Result := TMemoryStream.Create;

  case pID of

   0: TBlobField((fmMain.ActiveMDIChild as TfmAD).dbAD.FieldByName('ADPicture')).SaveToStream(Result);

//fmAD.dbAD.FieldByName('ADPicture')).SaveToStream(Result);

   1: TBlobField((fmMain.ActiveMDIChild as TfmTextSearch).RTFMatchTable.FieldByName('ADPicture')).SaveToStream(Result);

//fmTextSearch.RTFMatchTable.FieldByName('ADPicture')).SaveToStream(Result);

   2: TBlobField(fmRepCrit2A.qryAD.FieldByName('ADPicture')).SaveToStream(Result);

  end;

  Result.Position := 0;

  RichView2.Clear;

  RichView2.InsertRVFFromStream(Result, 0); // inserting will merge styles;

    // RichView1 and RichView2 have the same collections of styles

  Result.Clear;

  RichView2.SaveRVFToStream(Result, False);

  Result.Position := 0;

end;


procedure TfmRepCrit.Button2Click(Sender: TObject);

begin

  if not PreviewCreated then begin

    PreviewCreated := True;

    RVPrint1.AssignSource(rve1);

    RVPrint1.FormatPages(rvdoAll);

  end;

  // do not print empty document!

  if rve1.ItemCount=0 then

    exit;

  PrintDialog1.MinPage := 1;

  PrintDialog1.MaxPage := RVPrint1.PagesCount;

  PrintDialog1.FromPage := 1;

  PrintDialog1.ToPage := RVPrint1.PagesCount;

  // we can pring whole document or specified pages:

  if PrintDialog1.Execute then begin

    // it's possible that current printer was changed.

    // so we need to reformat document and update preview:

    RVPrint1.AssignSource(rve1);

    RVPrint1.FormatPages(rvdoAll);

    case PrintDialog1.PrintRange of

      prAllPages:

        RVPrint1.Print( 'Test', PrintDialog1.Copies, PrintDialog1.Collate);

      prPageNums:

        RVPrint1.PrintPages(PrintDialog1.FromPage, PrintDialog1.ToPage,

              'Test', PrintDialog1.Copies, PrintDialog1.Collate);

    end;

  end;

end;



"Sergey Tkachenko" <svt@trichview.com> wrote:

>Probably, these records were not written in the database.

>How do you write them?

>Please looks at the Example 1 in the help topic about TDBRichViewEdit

>

>> I am unable to preview/print specifc records in my database table. Viewing

>> the information is no problem. However, the records that don't show in

the

>> preview/printout are ones which I transferred

>> from a memo field to the blob field which was added to the table to handle

>> the RVF format. Other records which were later added are OK - these

>records

>> were imported using RVFImporter or simply copied and pasted into a

>> DBRichEdit field. So the problem is those records which were simply

>> transferred from memo to blob. I tested one of those records by cutting

>and

>> then repasting back into the record via DBRichEdit and it then shows up

on

>> the preview/printout after that. Is there an easy way to determine whether

>a

>> record contains a "problematic" blob field, one that won't be printing

>> properly, and to convert it to RVF format so it will show up in the

>> printouts.

>>

>> William Whitaker

>>

>>

>>

>>

>

>





Powered by ABC Amber Outlook Express Converter