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 ?
in c# this works:
rptDoc.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize) doctoprint3.PrinterSettings.PaperSizes[i3].RawKind
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.
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).
Met vriendelijke groet,
|
||||||||||||||||||||||
![]() |
||||||||||||||||||||||
Maurice Stassen
|
||||||||||||||||||||||
Software Engineer - Projectleider
|
||||||||||||||||||||||
![]() |
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
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).
Flag this post as spam/abuse.
Met vriendelijke groet,
|
||||||||||||||||||||||
![]() |
||||||||||||||||||||||
Maurice Stassen
|
||||||||||||||||||||||
Software Engineer - Projectleider
|
||||||||||||||||||||||
![]() |
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
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.
Flag this post as spam/abuse.