PaperSize CAST not working

Posted by mstassen on 10-Mar-2015 03:09

OE 11.5:

I want to set the PaperSize in a Crystal Reports document by:

DEF VAR clsPaperSize   AS CLASS System.Drawing.Printing.PaperSize.

DEF VAR clsReportDocument  AS CLASS CrystalDecisions.CrystalReports.Engine.ReportDocument.

clsReportDocument:PrintOptions:PaperSize = CAST(clsPaperSize:RawKind, CrystalDecisions.Shared.PaperSize).

The CAST is giving me a compile error, but why ? I copied the code from a c# .Net example that does work.

Any idea on how to do this ?

All Replies

Posted by mstassen on 10-Mar-2015 03:58

in c# this works:

rptDoc.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize) doctoprint3.PrinterSettings.PaperSizes[i3].RawKind

Posted by Laura Stern on 10-Mar-2015 08:40

clsPaperSize:RawKind is an integer.  CrystalDecisions.Shared.PaperSize is an Enumerator whose underlying value is an integer.  In the ABL you cannot use CAST to change an integer into an Enumerator.  In fact you cannot use CAST on an integer, period.  This is different than in C#.  

The way to do this would be to use the static ToObject method on System.Enum.  It takes a System.Type object, which would be the Type for a CrystalDecisions.Shared.PaperSize Enum and an integer which is the underlying value.  It will convert the specified 32-bit signed integer to an enumeration member.  Then you can assign it.  To get the Type object, you'd have to use Progress.Util.TypeHelper.GetType(" CrystalDecisions.Shared.PaperSize").

It might also be possible to do "NEW CrystalDecisions.Shared.PaperSize(clsPaperSize:RawKind)".  Not sure if you can do this, but if you can, it would give you an instance of the enum from the underlying value and then you can assign it.

A 3rd, non-elegant way to do this would be to use a CASE statement on the clsPaperSize:RawKind value and do the appropriate assignment within each case.  

Posted by Fernando Souza on 10-Mar-2015 08:59

This is an example on how to get this to work (as explained by Laura).

DEF VAR clsPaperSize   AS CLASS System.Drawing.Printing.PaperSize.

DEF VAR clsReportDocument  AS CLASS CrystalDecisions.CrystalReports.Engine.ReportDocument.

DEF VAR clsType AS CLASS System.Type.

clsType = Progress.Util.TypeHelper:GetType("CrystalDecisions.Shared.PaperSize").

clsReportDocument:PrintOptions:PaperSize = CAST (System.Enum:ToObject(clsType, clsPaperSize:RawKind),

                                                                                   CrystalDecisions.Shared.PaperSize).

Posted by mstassen on 10-Mar-2015 09:14

Thank you very much !!!
 
Met vriendelijke groet,
Maurice Stassen
Software Engineer - Projectleider
E-mail
Volg ons
LinkedIn
Facebook
Twitter
Twitter
Datamex
Datamex Automatisering B.V.
Minervum 7368, 4817 ZH Breda
Postbus 5515, 4801 DT Breda
Telefoon
Fax
Internet
(076) 5 730 730
(076) 5 877 757
www.datamex.nl
 
Van: Fernando Souza [mailto:bounce-fernando@community.progress.com]
Verzonden: dinsdag 10 maart 2015 15:00
Aan: TU.OE.Development@community.progress.com
Onderwerp: RE: [Technical Users - OE Development] PaperSize CAST not working
 
Reply by Fernando Souza

This is an example on how to get this to work (as explained by Laura).

DEF VAR clsPaperSize   AS CLASS System.Drawing.Printing.PaperSize.

DEF VAR clsReportDocument  AS CLASS CrystalDecisions.CrystalReports.Engine.ReportDocument.

DEF VAR clsType AS CLASS System.Type.

clsType = Progress.Util.TypeHelper:GetType("CrystalDecisions.Shared.PaperSize").

clsReportDocument:PrintOptions:PaperSize = CAST (System.Enum:ToObject(clsType, clsPaperSize:RawKind),

                                                                                   CrystalDecisions.Shared.PaperSize).

Stop receiving emails on this subject.

Flag this post as spam/abuse.

 
Dit E-mail bericht is op mogelijk schadelijke inhoud gecontroleerd door Kaspersky (www.kaspersky.com) en MailMarshal (www.marshal.com) en vrijgegeven!

Posted by mstassen on 10-Mar-2015 09:15

Thank you very much !!!
 
 
Met vriendelijke groet,
Maurice Stassen
Software Engineer - Projectleider
E-mail
Volg ons
LinkedIn
Facebook
Twitter
Twitter
Datamex
Datamex Automatisering B.V.
Minervum 7368, 4817 ZH Breda
Postbus 5515, 4801 DT Breda
Telefoon
Fax
Internet
(076) 5 730 730
(076) 5 877 757
www.datamex.nl
 
Van: Laura Stern [mailto:bounce-stern@community.progress.com]
Verzonden: dinsdag 10 maart 2015 14:41
Aan: TU.OE.Development@community.progress.com
Onderwerp: RE: [Technical Users - OE Development] PaperSize CAST not working
 
Reply by Laura Stern

clsPaperSize:RawKind is an integer.  CrystalDecisions.Shared.PaperSize is an Enumerator whose underlying value is an integer.  In the ABL you cannot use CAST to change an integer into an Enumerator.  In fact you cannot use CAST on an integer, period.  This is different than in C#.  

The way to do this would be to use the static ToObject method on System.Enum.  It takes a System.Type object, which would be the Type for a CrystalDecisions.Shared.PaperSize Enum and an integer which is the underlying value.  It will convert the specified 32-bit signed integer to an enumeration member.  Then you can assign it.  To get the Type object, you'd have to use Progress.Util.TypeHelper.GetType(" CrystalDecisions.Shared.PaperSize").

It might also be possible to do "NEW CrystalDecisions.Shared.PaperSize(clsPaperSize:RawKind)".  Not sure if you can do this, but if you can, it would give you an instance of the enum from the underlying value and then you can assign it.

A 3rd, non-elegant way to do this would be to use a CASE statement on the clsPaperSize:RawKind value and do the appropriate assignment within each case.  

Stop receiving emails on this subject.

Flag this post as spam/abuse.

 
Dit E-mail bericht is op mogelijk schadelijke inhoud gecontroleerd door Kaspersky (www.kaspersky.com) en MailMarshal (www.marshal.com) en vrijgegeven!

This thread is closed