View previous topic :: View next topic |
Author |
Message |
dbeau
Joined: 03 Feb 2005 Posts: 1
|
Posted: Thu Feb 03, 2005 8:36 pm Post subject: .NET Events |
|
|
I'm new to FTN95 and was looking for a little help.
I have a C# windows application that needs to receive custom events from my fortran assemblies. I've looked through documentation for any examples of how this might be accomplished. I was hoping that someone may have suggestions on how this can be done using FTN95.
Thanks,
dbeau |
|
Back to top |
|
|
Andrew
Joined: 09 Sep 2004 Posts: 232 Location: Frankfurt, Germany
|
Posted: Tue Feb 15, 2005 1:02 pm Post subject: .NET Events |
|
|
FTN95 for .NET does not have support for .NET events. The assemblies that are produced by FTN95 are designed more to be driven by say a C# frontend. Can you not have the event occur within some other .NET code (C# for example ) that then calls a required routine within an FTN95 .NET assembly? |
|
Back to top |
|
|
DrTip
Joined: 01 Aug 2006 Posts: 74 Location: Manchester
|
Posted: Sat Oct 28, 2006 2:35 pm Post subject: .NET Events |
|
|
I know this will be 2 years too late but I came up with a solution to this so I thought someone else might be interested since I wanted to to so the same. situation I want to solve was get rid of all FTN95 dos style screen outputs and let them be handled by c# form. fortran numerics is old code with lots of screen writes. the screen writing and logic were very intermingled. The idea is to minimise the amount of fortran changes, at most a search and replace type edit for screen writes.
solutions involves three bits an event handler - C# code this would in practice be a GUI. a C# event raiser and delegate class and the ftn95 code
this is stripped down C# driver/event handler ---- it calls calls the fotran code and catchs any events raised these are passed to the console but tey could be passed to file or a form or what ever by changing the method in the first line of code
using System;
using FTN95;
namespace asimpleeventhandler
{
class Program
{
static void Main(string[] args)
{
// define the .NET Console.Writeline to be the eroor handler (this could be a text box on a form or whatever.
FTN95.FTN95Outputs.FTN95Message+=new FTN95Outputs.FTN95WriteMessage(Console.WriteLine);
testharness.CALLCSHARP(); // call to FTN95 code
}
}
}
-- this is the FTN95 which just passes a message to the event raiser code in the case the message is "press any key"
subroutine callcsharp
!C# event LIBRARY is linked in to project
ASSEMBLY_EXTERNAL(NAME="FTN95.FTN95Outputs.STRINGOUT") writeout
integer k
call writeout("press any key")
call get_key@(k)
end subroutine
the event is raised by this little class
using System;
namespace FTN95
{
public class FTN95Outputs
{
// class that raises an event and passes a string to an error handler
public delegate void FTN95WriteMessage (string s); //funtion pointer for event handler
static public event FTN95WriteMessage FTN95Message; // event
static public void STRINGOUT(string s) //FTN95.NET calls this method which raises the event and passes message
{
if (FTN95Message!=null)
{
FTN95Message(s);
}
}
}
}
the point of going through all of this is that long fortran numerics might last for hours after pressing the "go button" The user likes to be informed that stuff is still happening if this was supplied by just strings to a console this can be quite tricky to unpick into the suggested of havig c# call lots of fucnitons. But here you don;t have to just call the event raiser with the message and let teh GUI worry about what to do with it.
also the messages can be sent to to places simulatneously files and teh screen just by having two event handlers respond to the same event.
hope someone finds that helpful.
The ftn95 compiler can't call .net 2.0 assemblies so the event raiuser has to be compiled with teh older csharp compiler. howver the .net 2.0 can call .net 1.0 assemblies well thats what I found.
if you compile and run above the message "press any key" is written to the screen
Carl
|
|
Back to top |
|
|
|