Recent

Author Topic: [SOLVED]fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt  (Read 5787 times)

Hopestation

  • Full Member
  • ***
  • Posts: 181
Hi.

I am using Windows10, Lazarus version #:1.8.0, FPC Version:3.0.4.

I have downloaded fpspreadsheet-1.8.4 and tried to use the example fpschart.lpr.

When I run it I get the following errors:

Compile Project, Target: fpschart.exe: Exit code 1, Errors: 1, Warnings: 2, Hints: 1
xlsxooxml.pas(291,6) Hint: Local const "ROWHEIGHT_EPS" is not used
wikitable.pas(495,59) Warning: Symbol "GetColWidth" is deprecated: "Use version with parameter AUnits."
wikitable.pas(501,60) Warning: Symbol "GetRowHeight" is deprecated: "Use version with parameter AUnits."
fpspreadsheetctrls.pas(3397,53) Error: Illegal type conversion: "TsCellFlags" to "LongInt"

This is the latest version, so why are these symbols depreciated and where do I get the version with parameter AUnits?

More important is the Illegal type conversion.

Why is this happening in an example taken straight from the source?

Surely other people have used this before me, so have I done something wrong?

Thanks.
« Last Edit: February 04, 2018, 05:12:09 pm by Hopestation »

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #1 on: February 02, 2018, 03:58:18 pm »
Strange, I cannot reproduce the error, only the hints and warnings. I am using Win 10 (64 bit), Laz 1.8/fpc3.04 (32 bit), fpspreadsheet 1.8.4. Are there any non-default compiler settings that you use?

The hints and warnings are no errors, they are just what their name says: Hints and warnings which indicate that something MAY be wrong, like decrementing a word variable which may lead to unexpected results if the result would expected to become negative. It is good programming style to look at them and to keep their count as low as possible. In fpspreadsheet trunk these warnings are removed (but others are introduced due to changes in LCL).

"deprecated" means: this feature has been available in the past, but there is a new one now; for some time both features are existing simultaneously until the old one will be removed. To notify the programmer that he is using the old feature, the keyword "deprecated" is added to the declaration. I am not very strict in removing deprecated features, therefore, there will always be some warnings of this kind.

Hopestation

  • Full Member
  • ***
  • Posts: 181
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #2 on: February 02, 2018, 09:25:34 pm »
Thanks for your comments.

I am using the following compiler options:-

Config files. Use standard compiler config file

Target OS.  Default for all.

Target-Specific options. win 32 gui application (-WG)

Current LCL widget set "win32"

Are these settings correct?

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #3 on: February 02, 2018, 10:45:31 pm »
Could you try this little demo:
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$mode objfpc}{$H+}    // <-- works
  4. //{$mode delphi}         // <--- does not work
  5.  
  6. uses
  7.   TypInfo;
  8.  
  9. type
  10.   TsCellFlag = (cfCalculating, cfCalculated, cfHasComment, cfHyperlink, cfMerged);
  11.   TsCellFlags = set of TsCellFlag;
  12.  
  13. var
  14.   flags: TsCellFlags;
  15.   s: String;
  16. begin
  17.   flags := [];
  18.   s := SetToString(PTypeInfo(TypeInfo(TsCellflags)), integer(flags), false);
  19.   WriteLn('[',s,']');
  20.  
  21.   flags := [cfCalculating];
  22.   s := SetToString(PTypeInfo(TypeInfo(TsCellflags)), integer(flags), false);
  23.   WriteLn('[',s,']');
  24.  
  25.   flags := [cfHasComment, cfHyperlink];
  26.   s := SetToString(PTypeInfo(TypeInfo(TsCellflags)), integer(flags), false);
  27.   WriteLn('[',s,']');
  28.  
  29.   ReadLn;
  30. end.

It compiles and runs fine for me if the {$mode objfpc} directive is used. However, if I change it to {$mode Delphi} then I get the error message that you report.

But what I don't understand is: {$mode...} is a unit-specific setting, and the unit fpsspreadsheetctrls does contain the objfpc directive. Did you change it?

In the previous post I forgot to explain the 
Quote
Warning: Symbol "GetColWidth" is deprecated: "Use version with parameter AUnits."
The Worksheet methods GetColWidth and GetRowHeight exist in two versions:
Code: Pascal  [Select][+][-]
  1.     function  GetColWidth(ACol: Cardinal): Single; overload; deprecated 'Use version with parameter AUnits.';
  2.     function  GetColWidth(ACol: Cardinal; AUnits: TsSizeUnits): Single; overload;
  3.   // the same with GetRowHeight
The old, deprecated one assumes that the column width is expressed as the count the characters "0" in the default font (like in old Excel versions). The new version supports a variety of size units (mm, cm, inches, etc), and this units must be specified in an additional parameter. If you add suChars as parameter then the warning is gone. And this is exactly how it is fixed in fpspreadsheet-trunk now.

Hopestation

  • Full Member
  • ***
  • Posts: 181
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #4 on: February 03, 2018, 06:32:51 pm »
Hi WP.

I'm sorry to say that I can't get the program to compile.

Not because of the previous problem, but because I am confused as to what to do with it.

I always start new projects as applications, so I get the lpi file and a form, with unit1.pas.

I tried transferring your text into my form code but it failed to compile with a message that writeln was invalid.

I added a memo to the form and used memo1.lines .add('[' + s + ']'); but it didn't work.

I have tried taking out the -WG target-specific option  but that deosn't work either.

Can you tell me how I should compile your example.

Incidentally. I ran the example straight from the fschart directory, without any changes, so it didn't have the Delphi option specified.

Thanks

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #5 on: February 03, 2018, 06:47:09 pm »
Sorry for my laziness not to prepare a full project.

But this is a console project, and this is easy: just copy the code from the forum post to the clipboard. Create a new project, but a console, not a GUI application, i.e. click "File" > "New..." >  "Project" > "Program". Then select the entire code skeleton and paste my code from the clipboard over it. Now you can compile and run.

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #6 on: February 03, 2018, 07:41:46 pm »
Could you open the unit fpspreadsheetctrls and add {$packset 4} to the header? I think it's obsolete, but who knows?

Code: Pascal  [Select][+][-]
  1. unit fpspreadsheetctrls;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$packset 4}                    // <--- NEW
  5.  
  6. interface  
  7. ....

Hopestation

  • Full Member
  • ***
  • Posts: 181
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #7 on: February 03, 2018, 08:01:09 pm »
Thanks.

I got it working by adding it into a project as a file. I had to add "interface" before Uses and

"implementation" before begin and cancel  the -WG option.

I get the same the same results as you when I swap between the Delphi and objfpc options.

I've never used a console application, so I wasn't familiar with what you have just described, but I've just done it and it makes sense now.

I tried adding {$packset 4} but it didn't help.

Thanks

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #8 on: February 03, 2018, 08:06:10 pm »
I am lost...

The only thing which I could imagine is that your installations somehow is screwed up. Would you mind to install Lazarus again?
  • Just select "secondary installation" in the setup program and you must select a configuration folder different from that of your old installation, then the new installation will not interfere with the old one (and you can just delete the new Lazarus and config folders if the new installation would not solve your issue).
  • When the new installation is complete, install the OnlinePackageManager (in "Package" > "Install/Unistall packages" find it in the right list of packages "available for installation", click "Install selection", then "Save and rebuild IDE")
  • When this is done and Lazarus has restarted, go to "Package" > "Online Package Manager". Find FPSpreadsheet, check it and click "Install"
  • Try the demo program again.
« Last Edit: February 03, 2018, 08:17:19 pm by wp »

Hopestation

  • Full Member
  • ***
  • Posts: 181
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #9 on: February 04, 2018, 01:12:55 pm »
Thanks, that's fixed it.

However, having run the demo I find that it only downloads data from a spreadsheet and plots the data on a chart on the form. I was expecting a demo showing how to create a chart in a spreadsheet. Is this possible in fpspreadsheet?

I have a dual boot system with Linux Mint Cinnamon 18.3.

I tried running the demo there but got messages saying that it could not compile files.

Lazarus is installed in File System/usr/lib and fpspreadsheet is in Lazarus/Components.

All this area is owned by root. Is this the problem? if it is, what's the answer?

I always learn something new when you help. I didn't know of the existence of Online Package Manager or Console operation.

Thanks for your help.

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #10 on: February 04, 2018, 02:44:02 pm »
Yep, probably a rights issue.
On Linux, I always install Lazarus in my home directory: ~/devel/lazarus

Bart

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #11 on: February 04, 2018, 03:20:09 pm »
having run the demo I find that it only downloads data from a spreadsheet and plots the data on a chart on the form. I was expecting a demo showing how to create a chart in a spreadsheet. Is this possible in fpspreadsheet?
No. FPSpreadsheet does not support charts embedded within the workbook or worksheet.

I have a dual boot system with Linux Mint Cinnamon 18.3.

I tried running the demo there but got messages saying that it could not compile files.

Lazarus is installed in File System/usr/lib and fpspreadsheet is in Lazarus/Components.

All this area is owned by root. Is this the problem? if it is, what's the answer?
I'm not so strong in Linux... On my Linux VM with trunk, Lazarus is installed in my home directory where I have full rights. Once I did a standard installation, all the files are owned by root.  Recompiling Lazarus resulted in a new version in my home directory. And there's a post by Juha these days saying that you should start Lazarus with "startlazarus" (https://forum.lazarus.freepascal.org/index.php?action=profile;u=2320)-

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: fpspreadsheet. Error: Illegal type conversion: "TsCellFlags" to "LongInt"
« Reply #12 on: February 04, 2018, 05:56:04 pm »
Once I did a standard installation, all the files are owned by root.  Recompiling Lazarus resulted in a new version in my home directory. And there's a post by Juha these days saying that you should start Lazarus with "startlazarus"
Startlazarus helps for running the Lazarus binary itself but not for demo projects. Demos and examples must be copied to a writable directory before they can be compiled. This is a limitation and there is currently no automation for it. In future the Tools -> Example Projects... could do it automatically.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018