Highlighted
Absent Member.
Absent Member.
2338 views

Callback function in Visual COBOL .NET

Jump to solution

Hello,

I´m trying to implement in Visual COBOL the following code (C#):

report.Render("Image", deviceInfo, CreateStream, out warnings);


CreateStream is not a dataitem but a function call... that is, a callback function defined previously as:

private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek) { Stream stream = new MemoryStream(); m_streams.Add(stream); return stream; }

I can´t get the way to translate that type of callback function call as a parameter of a COBOL INVOKE.

This is what I tried, but although it compiles, it doesn´t run (null exception):

INVOKE informe::Render("Image", deviceInfo, CreateStream, warnings).

And this is the definition of my Callback function:

delegate-id CreateStreamHandler.
procedure division using nombre as string, fileExtension as string, codificacion as type Encoding, mimeType as string, willSeek as condition-value
RETURNING stream as type Stream.
end delegate.
 

01 CreateStream type CreateStreamCallBack.

method-id CreateStreamCallBack.
procedure division USING nombre as string, fileExtension as string, codificacion as type Encoding, mimeType as string, willSeek as condition-value
RETURNING stream as type Stream.
SET stream TO New MemoryStream().
INVOKE m_streams::Add(stream).
end method.

The code I´m trying to replicate is located here:

http://msdn.microsoft.com/es-es/library/ms252091.aspx

Kind regards

0 Likes
1 Solution

Accepted Solutions
Highlighted
Absent Member.
Absent Member.

RE: Callback function in Visual COBOL .NET

Jump to solution

I got rid of the delegate and just renamed CreateStreamCallback method to CreateStream. Everything worked. Just I needed to learn the method parameter syntax.

View solution in original post

0 Likes
8 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Callback function in Visual COBOL .NET

Jump to solution

Hi jcamacho, I think you need to make two changes:

1) the parameters in CreateStreamCallBack need to be BY VALUE, so:

method-id CreateStreamCallBack.

procedure division USING BY VALUE nombre as string, fileExtension as string, codificacion as type Encoding, mimeType as string, willSeek as condition-value

2) since the parameter to the 'render' function is actually a method rather than a data item, it needs to be preceded by the keyword 'METHOD' and to provide the object (or type) on which the method is to act, so:

INVOKE informe::Render("Image", deviceInfo, method self::CreateStream, warnings).

I must say I'm surprised that the code in its existing state compiles - I would have expected a compile time error, but maybe I'm missing something.

Let me know if these modifications help.

Regards

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Callback function in Visual COBOL .NET

Jump to solution

I made the changes you suggested but it now shows me the following error:

Could not find method "Render" with this Signature.

See attached file.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Callback function in Visual COBOL .NET

Jump to solution

It's difficult to say why it's failing without seeing the whole application.  Is the Render method (in type LocalReport) declared with BY VALUE parameters?

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Callback function in Visual COBOL .NET

Jump to solution

I understand the difficulty.

The prototype for the method is:

Microsoft.Reporting.WinForms.Report::Render(format AS string, deviceInfo AS string, createStream AS Microsoft.Reporting.WinForms.CreateStreamCallback, REFERENCE warnings AS Microsoft.Reporting.WinForms.Warning OCCURS ANY)

Thank you for your suggestions. Robert

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Callback function in Visual COBOL .NET

Jump to solution

OK,

I finally made it working. I modified the INVOKE TO use the proper method name, not the dataitem.

INVOKE informe::Render("Image", deviceInfo, method self::CreateStreamCallback, warnings).

Which makes me think... Do I still need to have this method as an implementation for a delegate?

Kind regards

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Callback function in Visual COBOL .NET

Jump to solution

Hi, I'm not sure I understand the question.  If you're talking about the CreateStreamCallback method, I think the answer is yes, as you need to supply some code which will be the target of the delegate passed to the 'Render' method.  

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Callback function in Visual COBOL .NET

Jump to solution

I got rid of the delegate and just renamed CreateStreamCallback method to CreateStream. Everything worked. Just I needed to learn the method parameter syntax.

View solution in original post

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Callback function in Visual COBOL .NET

Jump to solution

Ah yes, you don't need to define your own delegate.  Glad you got it working...

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.