#1 2010-10-25 16:46:24

RyanMills
Member
Registered: 2010-10-25
Posts: 3

Can't compile latest version of code

Hi,

I'm posting this here because I didn't see another section to match it too.

I'm trying to evaluate the SynPDF stuff.

I downloaded the latest version of the open source code from version control this morning and tried to compile the htm2pdf demo.

I received an internal compiler error in SynCommons.pas terminating on the last line of

  function DeleteSection(SectionFirstLine: PUTF8Char; var Content: RawUTF8; EraseSectionHeader: boolean=true): boolean;

I'm running D2009, update 4.

Is this a known problem?  Do I have to do something special for D2009?

Ryan.

Offline

#2 2010-10-26 06:30:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Can't compile latest version of code

I compile the framework with Delphi 6, 7, 2007 and 2010 versions, before any source code release, and run all the unitary tests.
The current code was found out to be correct, compiling and running on all these compilers/IDE with no error.

Delete any previous dcu file, then compile it again.

Offline

#3 2010-10-26 14:46:54

RyanMills
Member
Registered: 2010-10-25
Posts: 3

Re: Can't compile latest version of code

First time downloading it was yesterday.

Since you don't test with D2009, I'll assume it's a D2009 thing.

I have XE so I'll try it there.

Ryan.

Offline

#4 2010-10-26 15:14:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Can't compile latest version of code

I don't have XE, so some feedback with this version is welcome.

Under Delphi 2010, it compiles with no warning at all, and the self tests runs as expected.

Thanks in advance.

Offline

#5 2010-10-26 21:43:55

RyanMills
Member
Registered: 2010-10-25
Posts: 3

Re: Can't compile latest version of code

Delphi XE seems to work fine.

Thanks for the component.

Offline

#6 2010-10-27 08:01:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Can't compile latest version of code

Good news!

Thanks for the feedback!

Offline

#7 2010-10-29 19:39:19

BenThon
Member
Registered: 2010-10-26
Posts: 11

Re: Can't compile latest version of code

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

Offline

#8 2010-10-29 22:15:26

BenThon
Member
Registered: 2010-10-26
Posts: 11

Re: Can't compile latest version of code

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 !

Offline

#9 2010-10-29 22:25:38

BenThon
Member
Registered: 2010-10-26
Posts: 11

Re: Can't compile latest version of code

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};

Offline

#10 2010-10-29 22:48:00

BenThon
Member
Registered: 2010-10-26
Posts: 11

Re: Can't compile latest version of code

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 !

Offline

#11 2010-10-29 23:09:12

BenThon
Member
Registered: 2010-10-26
Posts: 11

Re: Can't compile latest version of code

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 !

Offline

#12 2010-10-30 12:24:05

BenThon
Member
Registered: 2010-10-26
Posts: 11

Re: Can't compile latest version of code

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;

Offline

#13 2010-10-30 22:18:50

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Can't compile latest version of code

Thanks for the feedback.

I'll take a look and find the issue for the next SW release.

The Delphi 2009 compiler was definitively some kind of buggy...
Delphi 6 compiles our source code without any problem...

Offline

#14 2010-10-30 22:47:37

BenThon
Member
Registered: 2010-10-26
Posts: 11

Re: Can't compile latest version of code

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 !)

Offline

#15 2010-11-04 08:08:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Can't compile latest version of code

BenThon wrote:

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

As far as I discovered, the RichEdit version used in Delphi 6 (the first version we maintain) was already in version 2.0.

So I made some correction to TGDIPages.AppendRichEdit, using EM_GETTEXTLENGTHEX for getting the max length, since you reported some problems.

The Delphi 2009 specific NativeUInt issue is also corrected now.

Just uploaded the result to the source code repository.
See http://synopse.info/fossil/info/f87059cfaa

Merci pour le feedback smile

Offline

#16 2010-11-04 08:23:19

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Can't compile latest version of code

BenThon wrote:

Other suggestions. As with the PDF Document, add to the TGDIPages the Author, Subject and Keywords.
Merci. (C'est toujours bizarre de parler anglais entre français !)

I've added Author, Subject and Keywords optional parameters to TGDIPages.ExportPDF.
See http://synopse.info/fossil/info/5ce941a6e3

I continue to use ValidAnsi7 instead of AnsiString() conversion, because the PDF format only handle Ansi7 characters directly.

Offline

#17 2010-11-04 09:00:44

BenThon
Member
Registered: 2010-10-26
Posts: 11

Re: Can't compile latest version of code

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.

Offline

#18 2010-11-04 09:04:50

BenThon
Member
Registered: 2010-10-26
Posts: 11

Re: Can't compile latest version of code

PS : in your sample pdfrichedit if you use :


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

It preserves the rich text format.

Offline

#19 2010-11-08 07:29:03

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Can't compile latest version of code

BenThon wrote:

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

It will work indeed for WinAnsi encoded text.
I'll check this out and get rid of this ValidAnsi7 function.

Offline

#20 2010-11-22 22:05:20

BenThon
Member
Registered: 2010-10-26
Posts: 11

Re: Can't compile latest version of code

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

Offline

#21 2010-11-23 15:33:55

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Can't compile latest version of code

BenThon wrote:

A come back to your function AppendRichEdit. It seems that Delphi 2007 still uses Richedit version 1

There is a difference between the RichEdit Window Class name, and the dll used.

In all cases, it seems to me that the TGetTextLengthEx structure exists at least untill Delphi 6.
So I guess we can use TGetTextLengthEx without any problem.
Do you have any problem with the new code?

Offline

#22 2010-11-23 15:37:49

BenThon
Member
Registered: 2010-10-26
Posts: 11

Re: Can't compile latest version of code

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

Offline

#23 2010-11-23 15:57:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: Can't compile latest version of code

Thanks!

So I guess the current implementation is OK.
smile

Offline

Board footer

Powered by FluxBB