cannot use parameters from subroutine-header when calling Lahey Fortran 90 DLL from Delphi 3 
Author Message
 cannot use parameters from subroutine-header when calling Lahey Fortran 90 DLL from Delphi 3

Hello,

I am building a delphi application that uses a fortran DLL.
Whenever I use a parameter from the subroutine-header in the LF90-DLL
I get this message from within Delphi:

Project blabla raised exception class EAccessViolation with message
'Access violation at address 0044164E in module 'BDDEMO.DLL'. Read
of address 3F9C28F6. Process Stopped. Use Step etc.'

This is the relevant Delphi source:
type
  THoltropArray = array[1..100] of Single;
...
  procedure
Holtrop(    
                      NProp : LongInt; VK             : THoltropArray;
                      var RSW   : THoltropArray);
                      stdcall; external 'bddemo.dll';

The call:

  Do_The_Holtrop( iNProp, arVK, arRSW);

This is the source-code (a stripped version) of the DLL:

subroutine Do_The_Holtrop(nprop, VK, RSW)

   implicit none
   dll_export Do_The_Holtrop

   integer, parameter :: MaxSpeed = 100
   integer  :: nprop
   real, dimension( MaxSpeed ), intent(in) :: VK
   real, dimension( MaxSpeed ), intent(in out) :: RSW
   integer :: TA

      TA   = 0

      RSW = vk

      RSW(2) = nprop

end subroutine do_the_holtrop

When I replace

   RSW(2) = nprop

by

  RSW(2) = ta

everything works fine. I just cannot use the parameters from the
subroutine-header! Does anyone have suggestions?

I am using Windows 98 (brrr), Lahey Fortran 90 4.0 and Delphi
3.0.

Alex



Wed, 18 Jun 1902 08:00:00 GMT  
 cannot use parameters from subroutine-header when calling Lahey Fortran 90 DLL from Delphi 3
As I remember Pascal, if you use the keyword "var" you are
passing by reference, w/o it you are passing by value.

Fortran passes by reference; in most implementations in a
manner consistent with Pascal pass by reference (except
for varying length strings) so probably tacking "var" in front
of all the parameters in the Delphi declaration will get your
code on-track.  Even if that is not enough to solve all the
problems, I am sure it is a necessary first step.
--
Kevin G. Rhoads, Ph.D. (Linearity is a convenient fiction.)




Wed, 18 Jun 1902 08:00:00 GMT  
 cannot use parameters from subroutine-header when calling Lahey Fortran 90 DLL from Delphi 3

Quote:
>Fortran passes by reference; in most implementations in a
>manner consistent with Pascal pass by reference (except
>for varying length strings) so probably tacking "var" in front
>of all the parameters in the Delphi declaration will get your
>code on-track.

And it did. Thanks for the advise.

Alex



Wed, 18 Jun 1902 08:00:00 GMT  
 cannot use parameters from subroutine-header when calling Lahey Fortran 90 DLL from Delphi 3


...
My best guess would be that intent(in) doesn't in fact enforce pass-by-
value, so your Delphi is passing values which the Fortran considers to
be references. Try using var for all the variables in the Delphi
external definition.

If that doesn't work, check that "stdcall" is what Lahey uses. (I don't
know, but getting it wrong can cause the sort of thing you're seeing.)

Catherine.
--
Catherine Rees Lay



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Calling LaHey fortran 90 dll from delphi 3

2. beginner needs fortran 90 or lahey fortran90 subroutines (matrix)

3. Lahey Fortran 90 DLLs

4. Calling Fortran 90 subroutine from C program

5. Calling Fortran 90 DLL's from Borland C++ Builder

6. Teach myself Essential Lahey Fortran 90

7. Want to sell your Lahey Fortran 90 compiler?

8. Linking C into Lahey Fortran 90

9. interface block in Essential Lahey Fortran 90

10. !!!!URGENT!!!!! Help needed with Lahey Fortran 90

11. Best price for Lahey Fortran 90: Where?

 

 
Powered by phpBB® Forum Software