#1 Re: PDF Engine » Can't compile latest version of code » 2010-11-23 15:37:49

No, it's just for helping your code works with older Delphi versions.

#2 Re: PDF Engine » Can't compile latest version of code » 2010-11-22 22:05:20

A come back to your function AppendRichEdit. It seems that Delphi 2007 still uses Richedit version 1. See this on Embarcadero forum :
https://forums.embarcadero.com/thread.j … 8&tstart=0

#3 Re: PDF Engine » Can't compile latest version of code » 2010-11-04 09:04:50

PS : in your sample pdfrichedit if you use :


  RichEdit.Lines.LoadFromFile(ExtractFilePath(paramstr(0))+'testrtf.rtf');

It preserves the rich text format.

#4 Re: PDF Engine » Can't compile latest version of code » 2010-11-04 09:00:44

With AnsiString() and "minuscules accentuées" (le français, quoi !) it is ok ! But with your function ValidAnsi7, it is not good.

I am not sure that it is not handled by PDF. It works for me.

Thanks for your component and tking account of my suggestions.

#5 Re: PDF Engine » Can't compile latest version of code » 2010-10-30 22:47:37

Nevertheless for the AppendRichEdit, I think that my solution is adapted for using non plain text string from the RichEdit. Works with enhanced colored, styles, ... RichEdit. Works also with TJvRichEdit and derived TRichEdit.

Other suggestions. As with the PDF Document, add to the TGDIPages the Author, Subject and Keywords.
Like this :

      with PDF.Info do begin
        Title := ValidAnsi7(Caption);
        Name := ValidAnsi7(Application.Title);
        Creator := Name;
        Author := AnsiString(Auteur);
        Subject := AnsiString(Sujet);
        Keywords := AnsiString(MotsCles);
      end;

I prefer AnsiString than ValidAnsi7...

    /// the title of the report
    // - used for the preview caption form
    // - used for the printing document name
    Caption: string;
    Auteur: string;
    Sujet: string;
    MotsCles: string;
....

Thanks for the good work !

Merci. (C'est toujours bizarre de parler anglais entre français !)

#6 Re: PDF Engine » Can't compile latest version of code » 2010-10-30 12:24:05

Avec les modifications faites ci-dessus la fonction AppendRichEdit dans votre programme test pdfrichedit ne marche pas.

En l'adaptant ainsi, ça marche :

procedure TForm1.FormShow(Sender: TObject);
begin
  RichEdit.Lines.LoadFromFile(ExtractFilePath(paramstr(0))+'testrtf.rtf');
  //RichEdit.Text := StringFromFile(ExtractFilePath(paramstr(0))+'testrtf.rtf'); //Does not work !
end;

procedure TForm1.btnPDFClick(Sender: TObject);
begin
  with TGDIPages.Create(self) do
  try
    Caption := 'SynPDF RichEdit Print Preview & PDF Creation';
    BeginDoc;
    SaveLayout;
    Font.Size := 9;
    AddTextToHeaderAt(Caption,LeftMargin);
    TextAlign := taRight;
    AddTextToHeader(DateTimeToStr(Now));
    AddLineToHeader(true);
    TextAlign := taLeft;
    AddLineToFooter(true);
    AddPagesToFooterAt('Page %d/%d',LeftMargin);
    TextAlign := taRight;
    AddTextToFooterAt('-=- Test Right click on the report then "Export as PDF" -=-',RightMarginPos);
    RestoreSavedLayout;
    DrawTitle('Rich Edit Content',true);
    AppendRichEdit(RichEdit.Handle);
    DrawTitle('Last page content',true);
    NewHalfLine;
    DrawText('We are also able '+
      'to know at where Y position the RichEdit content was finished printing....'#13+
      'Therefore, any further writing to the report continue to the same page.');
    EndDoc;
    ExportPDF(ChangeFileExt(paramstr(0),'.pdf'),true,false);
    ShowPreviewForm;
  finally
    Free;
  end;
end;

et dans SQLite3Pages :

procedure TGDIPages.AppendRichEdit(RichEditHandle: HWnd);
var Range: TFormatRange;
    LogX, LogY, LastChar, MaxLen, OldMap: integer;
    TextLenEx: TGetTextLengthEx; // Added
    RichEditVersion : integer; // Added

begin
  with Range do begin
    LogX := GetDeviceCaps(fCanvas.Handle, LOGPIXELSX);
    LogY := GetDeviceCaps(fCanvas.Handle, LOGPIXELSY);
    rcPage.Left := (fPageMarginsPx.Left*1440) div LogX;
    rcPage.Right := ((fPhysicalSizePx.x-fPageMarginsPx.Right)*1440) div LogX;
    rcPage.Top := ((fPageMarginsPx.Top+fHeaderHeight)*1440) div LogY;
    rcPage.Bottom := ((fPhysicalSizePx.y-fPageMarginsPx.Bottom-fFooterHeight)*1440) div LogY;
    rc := rcPage;
    rc.Top := (fCurrentYPos*1440) div LogY;
    LastChar := 0;

// ___________________________________________________________________________
    {$if CompilerVersion >= 17}
      RichEditVersion := 2;     // Delphi 2005 or newer
    {$else}
      RichEditVersion := 1;     // I don't know when it was Version 1 !
    {$ifend}
    if RichEditVersion >= 2 then
    begin
      with TextLenEx do
      begin
        flags    := GTL_DEFAULT;
        codepage := CP_ACP;
      end;
      MaxLen := SendMessage(RichEditHandle,EM_GETTEXTLENGTHEX,wParam(@TextLenEx), 0);
    end
    else
      MaxLen := SendMessage(RichEditHandle, WM_GETTEXTLENGTH, 0, 0);
// ___________________________________________________________________________

    chrg.cpMax := -1;
    OldMap := SetMapMode(hdc, MM_TEXT);
    try
      SendMessage(RichEditHandle, EM_FORMATRANGE, 0, 0);
      repeat
        chrg.cpMin := LastChar;
        hdc := fCanvas.Handle;
        hdcTarget := hdc;
        LastChar := SendMessage(RichEditHandle, EM_FORMATRANGE, 1, Integer(@Range));
        if cardinal(LastChar)<cardinal(MaxLen) then begin
          NewPageInternal;
          DoHeader;
        end else
          fCurrentYPos := (rc.Bottom*LogY) div 1440;
        rc := rcPage;
      until (LastChar>=MaxLen) or (LastChar=-1);
    finally
      SendMessage(RichEditHandle, EM_FORMATRANGE, 0, 0);
      SetMapMode(hdc, OldMap);
    end;
  end;
end;

#7 Re: PDF Engine » Can't compile latest version of code » 2010-10-29 23:09:12

Donc en modifiant Synopse.inc (en ajoutant ISDELPHI2009) :

    {$if CompilerVersion >= 19}
      {$define ISDELPHI2007ANDUP} // Delphi 2007 or newer
    {$ifend}
    {$if CompilerVersion = 20}
      {$define ISDELPHI2009} // Delphi 2009
    {$ifend}

et en modifiant dans SynCommons :

{ ************ common types used for compatibility between compilers and CPU }

{$ifndef FPC} { make cross-compiler and cross-CPU types available to Delphi }
type
  /// a CPU-dependent unsigned integer type cast of a pointer / register
  // - used for 64 bits compatibility, native under Free Pascal Compiler
  {$ifdef ISDELPHI2009}
  PtrUInt = cardinal;
  {$else}
  PtrUInt = {$ifdef ISDELPHI2007ANDUP}NativeUInt{$else}cardinal{$endif};
  {$endif}
  /// a CPU-dependent unsigned integer type cast of a pointer of pointer
  // - used for 64 bits compatibility, native under Free Pascal Compiler
  PPtrUInt = ^PtrUInt;

  /// a CPU-dependent signed integer type cast of a pointer / register
  // - used for 64 bits compatibility, native under Free Pascal Compiler
  PtrInt = {$ifdef ISDELPHI2007ANDUP}NativeInt{$else}integer{$endif};
  /// a CPU-dependent signed integer type cast of a pointer of pointer
  // - used for 64 bits compatibility, native under Free Pascal Compiler
  PPtrInt = ^PtrInt;

  /// unsigned Int64 doesn't exist under older Delphi, but is defined in FPC
  QWord = {$ifdef ISDELPHI2007ANDUP}UInt64{$else}Int64{$endif};
{$endif}

Cela fonctionne !

#8 Re: PDF Engine » Can't compile latest version of code » 2010-10-29 22:48:00

Sans commenter la ligne dans Synopse.inc, mais en forçant :

PtrUInt = cardinal;

si on est avec Delphi 2009, alors tout marche comme il faut !

#9 Re: PDF Engine » Can't compile latest version of code » 2010-10-29 22:25:38

Mais si dans Synopse.inc on commente la ligne 140 comme ceci :

    {$if CompilerVersion >= 19}
//     {$define ISDELPHI2007ANDUP} // Delphi 2007 or newer
    {$ifend}

ça marche !!!

Donc le problème est ici :

type
  /// a CPU-dependent unsigned integer type cast of a pointer / register
  // - used for 64 bits compatibility, native under Free Pascal Compiler
  PtrUInt = {$ifdef ISDELPHI2007ANDUP}NativeUInt{$else}cardinal{$endif};
  /// a CPU-dependent unsigned integer type cast of a pointer of pointer
  // - used for 64 bits compatibility, native under Free Pascal Compiler
  PPtrUInt = ^PtrUInt;

  /// a CPU-dependent signed integer type cast of a pointer / register
  // - used for 64 bits compatibility, native under Free Pascal Compiler
  PtrInt = {$ifdef ISDELPHI2007ANDUP}NativeInt{$else}integer{$endif};
  /// a CPU-dependent signed integer type cast of a pointer of pointer
  // - used for 64 bits compatibility, native under Free Pascal Compiler
  PPtrInt = ^PtrInt;

  /// unsigned Int64 doesn't exist under older Delphi, but is defined in FPC
  QWord = {$ifdef ISDELPHI2007ANDUP}UInt64{$else}Int64{$endif};

#10 Re: PDF Engine » Can't compile latest version of code » 2010-10-29 22:15:26

Messages à la compilation sous Delphi 2009

[DCC Avertissement] SynCommons.pas(1786): W1022 La comparaison est toujours évaluée à True
[DCC Avertissement] SynCommons.pas(1790): W1021 La comparaison est toujours évaluée à False
[DCC Avertissement] SynCommons.pas(2266): W1022 La comparaison est toujours évaluée à True
[DCC Avertissement] SynCommons.pas(2271): W1021 La comparaison est toujours évaluée à False
[DCC Avertissement] SynCommons.pas(2444): W1022 La comparaison est toujours évaluée à True
[DCC Avertissement] SynCommons.pas(4655): W1023 Comparaison de types signés et non signés - opérandes agrandis
[DCC Erreur fatale] SynCommons.pas(4665): F2084 Erreur interne : C12079


et la compilation s'arrète à la ligne 4665 de SynCommons !

#11 Re: PDF Engine » Can't compile latest version of code » 2010-10-29 19:39:19

Thanks for the component !
But I have the same problem : Erreur interne à la compilation avec Delphi 2009 !

It works with Delphi 2007.

PS : serait-il possible d'avoir un exemple simple de création d'une page avec ce composant ? Merci d'avance

Board footer

Powered by FluxBB