Migrating FlexCel 3 to FlexCel 6 (Reports)

Finally I found some time to migrate FlexCel 3 to 6.
I installed the new FlexCel but now I see that my Reports continue to run using the old template format and keywords (like, for instance ##qry##field)

Here what I have done to install
1) uninstalled flexcel3
2) installed flexcel6 (the compilation took some time! :) )
3) opened RAD Studio XE4, and then one of my projects: FlexCelReport components not found.
4) close RAD Studio
4) installed flexcel3
5) project clean, build and run.

If I use a Template converted using the utility provided with FlexCel none of the new tags are replaced

What am I doing wrong?

Hi,


FlexCelReport in v6 isn't a component like in v3: it is  class. This is done in purpose, so you can - if you want - keep running some reports in FlexCel 3 with others in FlexCel 6 inside the same app. So there is no need to convert all the reports at the same time.

In order to allow this we couldn't make it a component, because you can't install a v6FlexCelReport and a v3FlexCelReport component at the same time in the Delphi IDE. So the component in the palette is a v3FlexCelReport only.

To use FlexCelReport 6 you would use it this way:

uses ... FlexCel.Report,...

var
  Report: TFlexCelReport;
begin
  if not SaveDialog.Execute then exit;

  Report := TFlexCelReport.Create(true);
  try
    Report.AddTable(DemoTables);
    Report.SetValue('Date', Now);
    Report.Run(
      TPath.Combine(GetDataPath, 'Range Reports.template.xls'),
      SaveDialog.FileName);
  finally
    Report.Free;
  end;

Note that there is an AddTable(...) method that you might call now that you didn't before. This addtable allows you to specify exactly which datasets, datamodules or list<object> you want to make available to a report. (while in FlexCel 3 it would always be the full datamodule where the FlexCelReport component was placed).

I took the example code above from the "Range reports" demo. But make sure to look at all the demos on there. FlexCelReport 6 isn't an incremental improvement over FlexCelReport 3; it is a complete new rethinking on how reports can be done (and this is why it took me so long to make them available to v6: It was all written from scratch). I made this rethinking when creating FlexCel .NET in 2003, based in all the experience I had since I first made my first report in 1996 in Delphi 1, and I think it is way better than the old engine. This is why I wanted to port the full thing to FlexCel for Delphi, and not just "improve" the v3 engine.

There is a lot of new stuff, and it is worth finding out. So make sure to run MainDemo.exe (from the start menu->tms FlexCel) and take a look at all the new demos showing how it works.

Also make sure to read "MigratingFromFlexCel3.pdf" in the "documentation" folder in start menu->tms FlexCel. It covers the basics on what is different from v3 to v6.

And remember, you can keep using the old FlexCel 3 reports while you migrate some reports. Migration isn't really difficult, but you do need to look at each project being migrated to see if conversion was fine.

I did read the doc about migrating FlexCel3 to 6, evidently I wasn't paying enough attention!

The class (v6) and the component (from v3) have the same name, so it will be a bit tricky to use both of them inside the same form, right?

Are the v3 reports compatible with the pdf export class?

Is v6 fully independent from v3 now?

Hi,



I would personally use different units for v3 and v6 reports, it will make things simpler. But it isn't so difficult to use both in the same unit if you want it. Just make sure that uFlexCelReport is before FlexCel.Report in your uses clause, and for the new reports, fully qualify the FlexCelReport class:



var
  Report: FlexCel.Report.TFlexCelReport;
begin
  if not SaveDialog.Execute then exit;


  Report :=  FlexCel.Report.TFlexCelReport.Create(true);
  try
    Report.AddTable(DemoTables);
    Report.SetValue('Date', Now);
    Report.Run(
      TPath.Combine(GetDataPath, 'Range Reports.template.xls'),
      SaveDialog.FileName);
  finally
    Report.Free;
  end;


But as said, I would personally use different units. With the new reports, you can AddTable(DataModule_From_V3) so the report doesn't need to be in the same place at the datamodule.


Yes, of course. Any xls/x file is compatible, even if it is not created by FlexCel. The advantage of v6 is that you can tun the report in the XlsFile directly, without needing to save it to a memorystream:



var
  Report: TFlexCelReport;
  Xls: TXlsFile;
begin
  Xls := TXlsFile.Create('template.xlsx', true);
  try
    Report :=  TFlexCelReport.Create(true);
    try
      Report.AddTable(DemoTables);
      Report.SetValue('Date', Now);
      Report.Run(Xls),
      ExportToPdf(Xls);
    finally
      Report.Free;
    end;
  finally
    Xls.Free;
  end;


With the old reports, you would have to save the result to a memorystream (or to a file), and then use that memorystream/file to export to pdf.

Now, if you use TXlsxAdapter instead of TXlsAdapter, the v3 reports will run with the v6 Engine, so the difference won't be that much as if you used TXlsAdapter. You can have xlsx reports with v3, they will be recalculated, etc. But it is just that the new report engine is much better, and will be better supported in the future. It will also run everywhere: OSX/iOS/Android, which you might not need today, but you might need in the future. So while not in a hurry, my advise would be to start migrating the reports.


v6 has always been fully independent from v3, you never needed to install v3 to use v6. v6 lacked some functionality present in v3, but it never used anything from v3. Today, the only thing still lacking in v6 but present in v3 is TFlexCelGrid. We haven't decided yet if we are going to do a FlexCelGrid v6 or not, but currently it would be the only thing missing.

Thanks Adrian (as always) for the prompt reply.

I started experimenting with v6 reports, just to see if I can convert all my templates to the new technology. I don't like to keep both flexcel 3 and 6, because it would mean to have two different syntax in my xls.

How do you call external functions? In v3 if you have a published Variant function in the form you can call it from the report Run.

Do I have to convert all my functions to TFlexCelUserFunction classes?


It depends on what the function does.

1)The simplest ones, you might replace them by report expressions. Say for example you have a function that is Uppercase().  You could create an expression in the config sheet that is:

Uppercase(text) = <#evaluate(UPPER(text))>
Or you could write in the cell directly <#evaluate(UPPER(<#Somedb.Field>))> and not use any user function.Due to the fact that you can use any Excel function in <#evaluate>, and you have <#if..> tags and others, most of the functions that you needed to define in v3 are not needed anymore.

2)For more complex functions, but which don't take arguments and part of the data (not datasets), you can use a public (or published) function in the data.

For example if you have  a class
  TCustomer = class
     public
         funciton NameGUID: string;
  end;

and you AddTable(someList<TCustomer>), then you can write <#Customer.NameGUID> in the template, and the function will be called.

3)If both 1) and 2) aren't possible, yes, you'll have to define a TFlexCelUserFunction class and add it with AddUserFunction. But in my experience, for most stuff, you don't really need user functions anymore. Those were needed in v3 because the tag engine was much more limited.
Adrian Gallero2014-12-23 07:55:43

Ok thank you very much. I think the migration process won't be so traumatic, after all.

As a side note: the installation process took a couple of hours, is it normal? v3 installs in a blink of an eye...

Normal it isn't: The installation procedure should take a couple of minutes, not a couple of hours. But I've seen reports from other people who had the same situation (I think you can see in this same newsgroup a complain that it took 8 hours) and I really wonder what can make such a big difference. 


Starting by the beginning: FlexCel 6 is way slower to install than FlexCel 3. This is not only because it has 1700 units, but also because we install it for OSX, iOS, Win64 and Android. And all of those compilers are an order of magnitude slower than our old dear Win32 compiler (which is the only one FlexCel 3 installs). So if you need to speed up and you don't care about more platforms, the first thing to make the install faster is to select only win32. I suspect much of the slowdown is in the mobile compilers anyway.

Besides the mobile/win64/osx compilers (5 different ones) we also compile for debug and release, which doubles the compile time. The debug dcus are used if you select "Use debug dcus" in the compiler options, and they allow you to step through FlexCel code. While the release dcus will jump over the FlexCel code, just like the VCL itself. So we have 2 * 5 = 10 different compilations. I think we have 7 packages, so that is 70 packages to be compiled. (If you are installing for a single delphi XE version). And packages are slow to compile, mainly because they use generics a lot, and generics are slower to compile than non-generic code.

Now, about why I see about 5 minutes here (in a 2010 i7 with 8gb ram, no SSD), you see 2 hours and other customer sees 8 hours, I am not really sure. I wonder if the Antivirus could have something to do?  As there are 1700 files to compile, with 10 compilers (including debug and release) and every one of those 1700 units includes a FLEXCEL.INC which in turn includes FLXCOMPILER.INC, we are speaking about 1700102 files that must be opened (if the compiler doesn't cache the .inc, I am not sure if it does). If the AntiVirus is slow in each file, that time could sum up.

But well, no matter how slow to install, it shouldn't affect the time spent to compile once it is installed. The only thing is that there is maybe something in your machine that you could fix to make everything compile faster (not only FlexCel)

It doesn't seem to affect the performance of the compiler in my project, so is not a big deal. I don't plan to reinstall FlexCel 6 very often :)
I use RAD Studio inside a VM (VirtualBox). For some reason it slows the compilation time and the auto-completion (especially C++ Builder) but not so much. I have never found why.

If I have any more clues about this I will let you know.