Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: $IFDEF for fast report component.


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 8 - Last Post: Jan 26, 2015 3:38 AM Last Post By: Ste War
Ste War

Posts: 31
Registered: 1/9/15
$IFDEF for fast report component.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 18, 2015 4:32 AM
Delphi XE 7.

I have adding a fastreport 2.o FMX report onto my form

When I switch to mobile I get errors.

I can fix the design time uses errors by by

($IF DEFINED (MSWINDOWS) }

uses FMX.frxClass

{$ENDIF}

but when I run the app on mobile it adds FMX.frxClass to the uses and fails

Also I can work out the syntax to do the same with the type eg

frxReport1: TfrxReport

What is the correct method for components that are not available on mobile.

Thanks
Eduardo Elias

Posts: 319
Registered: 9/20/12
Re: $IFDEF for fast report component.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 18, 2015 4:54 AM   in response to: Ste War in response to: Ste War
There are missing information here, I suppose you are working on a form.

If you remove the unit for fastreport and you still have references to it
on the form the delphi IDE will automatically add the uses back again.

the correct manner in this case is that:

- having separated forms, one for windows and another for mobile. Where you
add the propert unit using {$IFDEF} for each case
- not using fastreport as a control on the form. In this case you create
everything on the fly, manually, and then you can surround this code with
{$IFDEF} to no be executed when compiled to mobile

you should not use ifdefs with forms declarations, one part of the declaration
is in the class, but there is form stream, and that is out of reach for IFDEF.

Delphi XE 7.

I have adding a fastreport 2.o FMX report onto my form

When I switch to mobile I get errors.

I can fix the design time uses errors by by

($IF DEFINED (MSWINDOWS) }

uses FMX.frxClass

{$ENDIF}

but when I run the app on mobile it adds FMX.frxClass to the uses and
fails

Also I can work out the syntax to do the same with the type eg

frxReport1: TfrxReport

What is the correct method for components that are not available on
mobile.

Thanks
Stev Warby

Posts: 50
Registered: 10/19/14
Re: $IFDEF for fast report component.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 20, 2015 4:04 AM   in response to: Eduardo Elias in response to: Eduardo Elias
Hi Eduatdos,

I am not understanding the concept here.

I was presuming I could build a firemonkey app with some reports but 'switch off' them when running on mobile.

When I add another form to the project and then add a report component I still get the error

Can't resolve unit name FMX.frxClass & Undeclared Identifier TfrxReport.

So what is the correct procedure to do this ?

I presume I add the new form to the uses of the first form (not done this before I have just used a tabControl).

Then call the reports (new form) only if on windows or Mac.

Thanks....

Eduardo Elias

Posts: 319
Registered: 9/20/12
Re: $IFDEF for fast report component.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 20, 2015 4:21 AM   in response to: Stev Warby in response to: Stev Warby
for example, if you are creating a project for Android, you cannot have
units that are not supported on that platform.

There is no FastReport yet for Android or iOS.

So when you compile for that platform you cannot have the unit declared.

For that you need to use the $IFDEF, only allowing it on the platforms that
you want.

What I told you is not to use one unit full of IFDEFS, instead, create a
unit for mobile and another for the rest.

Then you include the mobile unit when you targeting mobile..... otherwise
use the other unit....

Only you will use FastReport on the unit that is not for mobile.

based on what you said on your first post, you are including units that are
not compatible, not supported on mobile. You need to pay attention to that.
You can create the application for windows, but just trying to compile to
another platform will not work. If you need to have reports on all the platforms
you need to use something else, like FlexCel from TMS, since FastReports
do not suppor all platforms.

Hi Eduatdos,

I am not understanding the concept here.

I was presuming I could build a firemonkey app with some reports but
'switch off' them when running on mobile.

When I add another form to the project and then add a report component
I still get the error

Can't resolve unit name FMX.frxClass & Undeclared Identifier
TfrxReport.

So what is the correct procedure to do this ?

I presume I add the new form to the uses of the first form (not done
this before I have just used a tabControl).

Then call the reports (new form) only if on windows or Mac.

Thanks....
Stev Warby

Posts: 50
Registered: 10/19/14
Re: $IFDEF for fast report component.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 24, 2015 1:55 AM   in response to: Eduardo Elias in response to: Eduardo Elias
Hi Eduardo,

I am still not understanding the methods to use.
I have tried:

Add another form (reports).
Do not add this form to the uses of the main form.
I then add a report component onto the report form.
When I switch to mobile I get an error.

So I tried :

uses

{$IF DEFINED(MSWINDOWS) or DEFINED(MACOS)}

System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.frxClass;

{$ENDIF}

{$IF DEFINED(iOS) or DEFINED(ANDROID)}

System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs;

{$ENDIF}

type
TForm3 = class(TForm)
{$IF DEFINED(MSWINDOWS) or DEFINED(MACOS)}
frxReport1: TfrxReport;

{$ENDIF}

But when I run the app this gets added to the report form :

uses System.Classes, FMX.frxClass;

and I get the error again.

What is the correct way to do this ?

Thanks...

Eduardo Elias

Posts: 319
Registered: 9/20/12
Re: $IFDEF for fast report component.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 24, 2015 3:55 AM   in response to: Stev Warby in response to: Stev Warby
Do you have a FastReport component in your form right?

If so, this is the problem. Even that you create this DEFINES, you have a
component in the form that should not be there when compiling to mobile.

When you open your form, delphi IDE will try to help you and will add the
units in order to make that component compile correctly.

You have 2 options:

1 - do not use the component in the form

you will need to create in manually. Declare it on your form class and create
it on FormCreate. But only do that if you are not targeting mobile.

2 - better: create 2 different units. One for mobile and other for desktop.
Then you are not going to have a lot of DEFINES in you source. In this case
you need to add the DEFINE in your project file or in the MainForm:

use
{$IF DEFINED(MSWINDOWS) or DEFINED(MACOS)}
"formdesktop"
{$ELSE}
"formmobile"
{$ENDIF}

this way, when you compile the application the correct version of your form
will be compiled. If it is windows for example, it will use the "formdesktop"
where you have FastReports. The other version will not have it at all.

Does it get clearer to you?

Hi Eduardo,

I am still not understanding the methods to use.
I have tried:
Add another form (reports).
Do not add this form to the uses of the main form.
I then add a report component onto the report form.
When I switch to mobile I get an error.
So I tried :

uses

{$IF DEFINED(MSWINDOWS) or DEFINED(MACOS)}

System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.frxClass;
{$ENDIF}

{$IF DEFINED(iOS) or DEFINED(ANDROID)}

System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs;
{$ENDIF}

type
TForm3 = class(TForm)
{$IF DEFINED(MSWINDOWS) or DEFINED(MACOS)}
frxReport1: TfrxReport;
{$ENDIF}

But when I run the app this gets added to the report form :

uses System.Classes, FMX.frxClass;

and I get the error again.

What is the correct way to do this ?

Thanks...
Ste War

Posts: 31
Registered: 1/9/15
Re: $IFDEF for fast report component.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 24, 2015 7:21 AM   in response to: Eduardo Elias in response to: Eduardo Elias
I am following what you are saying.


I have changed the main form to :

uses
{$IF DEFINED(MSWINDOWS) or DEFINED(MACOS)}
reports;
{$ENDIF}

{$IF DEFINED(iOS) or DEFINED(ANDROID)}
reportsMobile;
{$ENDIF}

On the reports form I have

uses Data.DB, Datasnap.DBClient, DBAccess, MyAccess,
System.Classes, FMX.Types, FMX.Controls, FMX.StdCtrls,

{$IF DEFINED(MSWINDOWS) or DEFINED(MACOS)}

System.SysUtils, System.Types, System.UITypes, System.Variants,
FMX.Forms, FMX.Graphics, FMX.Dialogs, MainPage,

{$ENDIF}
{$IF DEFINED(iOS) or DEFINED(ANDROID)}
Data.DB, Datasnap.DBClient, DBAccess, MyAccess,
System.Classes, FMX.Types, FMX.Controls, FMX.StdCtrls;
{$ENDIF}

{$IF DEFINED(iOS) or DEFINED(ANDROID)}
Data.DB, Datasnap.DBClient, DBAccess, MyAccess,
System.Classes, FMX.Types, FMX.Controls, FMX.StdCtrls;
{$ENDIF}


But when I compileS the IDE is automatically adds uses ( FMX.frxClass,
FMX.frxDBSet,)

uses Data.DB, Datasnap.DBClient, DBAccess, MyAccess,
System.Classes, FMX.Types, FMX.Controls, FMX.StdCtrls, FMX.frxClass,
FMX.frxDBSet,

I then get the following error:

[dcc64 Error] reports.pas(15): E2004 Identifier redeclared: 'FMX.frxClass'
[dcc64 Error] reports.pas(15): E2004 Identifier redeclared: 'FMX.frxDBSet'

I'm going round in circles here so I presume I am doing something dumb here.

Thanks...

Eduardo Elias

Posts: 319
Registered: 9/20/12
Re: $IFDEF for fast report component.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 24, 2015 9:46 AM   in response to: Ste War in response to: Ste War
I am following what you are saying.

I have changed the main form to :

uses
{$IF DEFINED(MSWINDOWS) or DEFINED(MACOS)}
reports;
{$ENDIF}
{$IF DEFINED(iOS) or DEFINED(ANDROID)}
reportsMobile;
{$ENDIF}

That is ok

On the reports form I have

uses Data.DB, Datasnap.DBClient, DBAccess, MyAccess,
System.Classes, FMX.Types, FMX.Controls, FMX.StdCtrls,
{$IF DEFINED(MSWINDOWS) or DEFINED(MACOS)}

System.SysUtils, System.Types, System.UITypes, System.Variants,
FMX.Forms, FMX.Graphics, FMX.Dialogs, MainPage,
{$ENDIF}
{$IF DEFINED(iOS) or DEFINED(ANDROID)}
Data.DB, Datasnap.DBClient, DBAccess, MyAccess,
System.Classes, FMX.Types, FMX.Controls, FMX.StdCtrls;
{$ENDIF}
{$IF DEFINED(iOS) or DEFINED(ANDROID)}
Data.DB, Datasnap.DBClient, DBAccess, MyAccess,
System.Classes, FMX.Types, FMX.Controls, FMX.StdCtrls;
{$ENDIF}
But when I compileS the IDE is automatically adds uses ( FMX.frxClass,
FMX.frxDBSet,)
uses Data.DB, Datasnap.DBClient, DBAccess, MyAccess,
System.Classes, FMX.Types, FMX.Controls, FMX.StdCtrls, FMX.frxClass,
FMX.frxDBSet,

Why you still have these defines if this unit "reports" is meant for windows/macos
only?

You have now 2 units, one called "reports" and another "reportsmobile". There
is no need to have any $Defines inside them.

I then get the following error:

[dcc64 Error] reports.pas(15): E2004 Identifier redeclared:
'FMX.frxClass' [dcc64 Error] reports.pas(15): E2004 Identifier
redeclared: 'FMX.frxDBSet'

I'm going round in circles here so I presume I am doing something dumb
here.

Thanks...

Another thing, the "reportsmobile" should not have any component from fastreports.
Did you make a copy and past of the unit and form in order to create these
units? probably you left the components on the form.

Like I said, Delphi IDE will add always the units that are missing when you
have a component on the form and there is a missing unit. You need to check
what components you have in your MOBILE form. And remove all those that are
related to FastReports. I believe there is the FastReport Dataset in there.
Ste War

Posts: 31
Registered: 1/9/15
Re: $IFDEF for fast report component.  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jan 26, 2015 3:38 AM   in response to: Eduardo Elias in response to: Eduardo Elias
Hi,

try the following

open a new cross platform application.

Add a new form called reports.

Add a fastreport component to that page.

No matter what you do with the ifdefs it fails when switching to mobile platform.

Thanks...
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02