0

I downloaded HB-Report (https://sourceforge.net/projects/hb-reports/), but when I try to use it in a FireMonkey Android project, the PlatformExtensions gives an error. When I try to add the Android extension to the unit, a different error shows.

For more detail, download the component, I'm trying to use this component on Android.

This is the unit:

{*****************************************************************************}
{                                                                             }
{   This file is part of the HBReports components Library                     }
{                                                                             }
{   See the file COPYING.LGPL.txt included in this distribution,              }
{   for details about the Licence and Copyright.                              }
{                                                                             }
{   This code is distributed in the hope that it will be useful,              }
{   but WITHOUT ANY WARRANTY; without even the implied warranty of            }
{   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                      }
{                                                                             }
{   Author: Leslie John Kaye :    www.leskaye.com                             }
{                                                                             }
{   Abstract:                                                                 }
{      Platform extensions                                                               }
{                                                                             }
{*****************************************************************************}


    unit FMX.PlatformExtensions;
    
    interface
    
    uses
      System.Classes,
    {$IFDEF MSWINDOWS}
      System.AnsiStrings, Winapi.Windows//, WinProcs
    {$ENDIF}
    {$IFDEF MACOS)}
      Macapi.CoreFoundation, Macapi.Foundation, MacApi.Appkit
    {$ENDIF MACOS}
     {$ifdef Android}
      FMX.Helpers.Android, AndroidAPI.Helpers,
      AndroidApi.JNI.GraphicsContentViewText,
      AndroidApi.JNI.Net, AndroidApi.JNI.JavaTypes;
      {$endif Android}
    
    type
      TPlatformExtensions = class(TObject)
      public
        class procedure GetSystemFonts(FontList: TStrings);
       end;
    var
      PlatformExtensions:TPlatformExtensions;
    
    implementation
    
    { TPlatformExtensions }
    
    class procedure TPlatformExtensions.GetSystemFonts(FontList: TStrings);
     {$ifdef Android}
    {$IFDEF MSWINDOWS}
    var
    Context: HDC;
    Font: TLogFont;
    
      function EnumFontsList(var LogFont: TLogFont; var TextMetric: TTextMetric;
      FontType: Integer; Data: Pointer): Integer; stdcall;
      var
        List: TStrings;
        FName: string;
      begin
        List := TStrings(Data);
        FName := LogFont.lfFaceName;
        if (List.Count = 0) or (List.IndexOf(FName) <> List.Count-1) then
          List.Add(FName);
        Result := 1;
      end;
    
    begin
      Context := GetDC(0);
      FillChar(Font, sizeof(Font), 0);
      Font.lfCharset := DEFAULT_CHARSET;
      EnumFontFamiliesEx(Context, Font, @EnumFontsList, Winapi.Windows.LPARAM(FontList), 0);
      ReleaseDC(0, Context);
    {$ENDIF}
    {$IFDEF MACOS)}
    var
      Manager: NsFontManager;
      List: NSArray;
      Item: NSString;
      I: Integer;
    begin
      Manager := TNsFontManager.Wrap(TNsFontManager.OCClass.sharedFontManager);
      List := Manager.availableFontFamilies;
      if (List <> nil) and (List.Count > 0) then
      begin
        for I := 0 to List.Count-1 do
        begin
          Item := TNSString.Wrap(List.objectAtIndex(I));
          FontList.Add(String(Item.UTF8String));
        end;
      end;
    {$ENDIF MACOS}
    
    //end;
    
    
    initialization
      PlatformExtensions := TPlatformExtensions.Create;
    
    finalization
      PlatformExtensions.Free;
    
    end.
    Checking project dependencies...
    Compiling Project1.dproj (Debug, Android)
    dccaarm command line for "Project1.dpr"
      c:\program files (x86)\embarcadero\studio\20.0\bin\dccaarm.exe -$O- --no-config -M -Q -TX.so -AGenerics.Collections=System.Generics.Collections;
      Generics.Defaults=System.Generics.Defaults;WinTypes=Winapi.Windows;WinProcs=Winapi.Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE -DDEBUG 
      -E.\Android\Debug -I"c:\program files (x86)\embarcadero\studio\20.0\lib\Android\debug";"c:\program files 
      (x86)\embarcadero\studio\20.0\lib\Android\Release" -LEC:\Users\Public\Documents\Embarcadero\Studio\20.0\Bpl\Android 
      -LNC:\Users\Public\Documents\Embarcadero\Studio\20.0\Dcp\Android -NU.\Android\Debug -NSSystem;Xml;Data;Datasnap;Web;Soap; -O"c:\program files 
      (x86)\embarcadero\studio\20.0\lib\Android\Release" -R"c:\program files (x86)\embarcadero\studio\20.0\lib\Android\Release" -U"c:\program files 
      (x86)\embarcadero\studio\20.0\lib\Android\debug";"c:\program files (x86)\embarcadero\studio\20.0\lib\Android\Release" 
      --linker:C:\Users\Public\Documents\Embarcadero\Studio\20.0\PlatformSDKs\android-ndk-r17b\toolchains\arm-linux-androideabi-4.9\prebuilt\windows\bin\arm-linux-androideabi-ld.exe 
      -V -VN -NO.\Android\Debug  Project1.dpr
    [DCC Error] FMX.PlatformExtensions.pas(99): E2029 'BEGIN' expected but 'INITIALIZATION' found
    [DCC Fatal Error] FMX.PlatformExtensions.pas(51): E2280 Unterminated conditional directive
    Failed
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Welcome to StackOverflow! You say "...give an error". Please specify which error EXACTLY you received and where EXACTLY you get it. Beside that remark, the error listed in the compiler output you show is pretty clear: you have a ´begin´ without a matching ´end´. – fpiette Nov 01 '20 at 13:42
  • 1
    But it is said on the site you linked to: *For Delphi and C++ Builder, VCL and Firemonkey, **Win32, Win64 and OSX***. Why do you think it would work on Android? – Tom Brunberg Nov 01 '20 at 15:04

1 Answers1

0

{$IFDEF MACOS)} needs to be {$IFDEF MACOS}, there is an erroneous ) that needs to be removed.

More importantly, the {$ifdef Android} inside the implementation of TPlatformExtensions.GetSystemFonts() is incomplete. There is no matching {$endif}, as the 2nd error message says. And there is no begin/end to define the body of the procedure. When compiling for Android, the compiler is encountering the initialization before a begin, exactly as the 1st error message says.

There are several other syntax errors in this code, as well.

Try something more like this:

{*****************************************************************************}
{                                                                             }
{ This file is part of the HBReports components Library                       }
{                                                                             }
{ See the file COPYING.LGPL.txt included in this distribution,                }
{ for details about the Licence and Copyright.                                }
{                                                                             }
{ This code is distributed in the hope that it will be useful,                }
{ but WITHOUT ANY WARRANTY; without even the implied warranty of              }
{ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                        }
{                                                                             }
{ Author: Leslie John Kaye : www.leskaye.com                                  }
{                                                                             }
{ Abstract:                                                                   }
{ Platform extensions                                                         }
{                                                                             }
{*****************************************************************************}

unit FMX.PlatformExtensions;

interface

uses
  System.Classes
  {$IFDEF MSWINDOWS}
  ,System.AnsiStrings, Winapi.Windows//, WinProcs
  {$ENDIF}
  {$IFDEF MACOS}
  ,Macapi.CoreFoundation, Macapi.Foundation, MacApi.Appkit
  {$ENDIF MACOS}
  {$IFDEF ANDROID}
  ,FMX.Helpers.Android, AndroidAPI.Helpers, AndroidApi.JNI.GraphicsContentViewText, AndroidApi.JNI.Net, AndroidApi.JNI.JavaTypes
  {$ENDIF ANDROID}
  ;

type
  TPlatformExtensions = class(TObject)
  public
    class procedure GetSystemFonts(FontList: TStrings);
  end;

var
  PlatformExtensions: TPlatformExtensions;

implementation

{ TPlatformExtensions }

class procedure TPlatformExtensions.GetSystemFonts(FontList: TStrings);
{$IFDEF MSWINDOWS}
var
  Context: HDC;
  Font: TLogFont;

  function EnumFontsList(var LogFont: TLogFont; var TextMetric: TTextMetric; FontType: Integer; Data: Pointer): Integer; stdcall;
  var
    List: TStrings;
    FName: string;
  begin
    List := TStrings(Data);
    FName := LogFont.lfFaceName;
    if (List.Count = 0) or (List.IndexOf(FName) <> List.Count-1) then
      List.Add(FName);
    Result := 1;
  end;
{$ENDIF MSWINDOWS}
{$IFDEF MACOS}
var
  Manager: NsFontManager;
  List: NSArray;
  Item: NSString;
  I: Integer;
{$ENDIF MACOS}
{$IFDEF ANDROID}
// TODO
{$ENDIF ANDROID}
begin
  {$IFDEF MSWINDOWS}
  Context := GetDC(0);
  FillChar(Font, sizeof(Font), 0);
  Font.lfCharset := DEFAULT_CHARSET;
  EnumFontFamiliesEx(Context, Font, @EnumFontsList, Winapi.Windows.LPARAM(FontList), 0);
  ReleaseDC(0, Context);
  {$ENDIF}
  {$IFDEF MACOS}
  Manager := TNsFontManager.Wrap(TNsFontManager.OCClass.sharedFontManager);
  List := Manager.availableFontFamilies;
  if (List <> nil) and (List.Count > 0) then
  begin
    for I := 0 to List.Count-1 do
    begin
      Item := TNSString.Wrap(List.objectAtIndex(I));
      FontList.Add(String(Item.UTF8String));
    end;
  end;
  {$ENDIF MACOS}
  {$IFDEF ANDROID}
  // TODO
  {$ENDIF ANDROID}
end;

initialization
  PlatformExtensions := TPlatformExtensions.Create;

finalization
  PlatformExtensions.Free;

end.
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • not working, can you download the HB Report and try to used on firemonkey android this is the link https://sourceforge.net/projects/hb-reports/ – Edgar Polanco Nov 02 '20 at 00:27
  • @EdgarPolanco I do not have an IDE installed right now, so I cannot try to compile the code myself. But I have now updated my answer with code that should compile, though you will still have to update the code to [enumerate the fonts on Android](https://stackoverflow.com/questions/3532397/). – Remy Lebeau Nov 02 '20 at 05:54