• delphi, vba & dll

    From Renato Zambon@1:2320/100 to All on Sat Apr 3 15:55:08 2004
    Oi,

    Tenho um problema encalhado aqui: uma DLL, feita em Fortran (Compaq
    Visual Fortran), e que era chamada originalmente dentro do Excel com
    VBA, e estou mudando o sistema do Excel para o Delphi 7.

    Para alguns dados, j  roda igual nos dois, mas para outros, d  o
    seguinte erro:

    ---------------------------
    Debugger Exception Notification
    ---------------------------
    Project SisOpt.exe raised exception class EInvalidOp with message
    'Invalid floating point operation'. Process stopped. Use Step or Run
    to continue.
    ---------------------------

    Esse erro ocorre durante a execu‡Ćo da DLL, ela roda uma parte (faz
    alguns c lculos, gera arquivos, chama um outro prg externo para
    processar eles, ele roda e completa normal, mas depois disso a DLL
    aborta com o erro) S˘ ocorre quando chamado pelo Delphi, no Excel/
    VBA roda ok at‚ o fim.

    J  tentei mapear os valores de todas as +200mil vari veis passadas
    para a dll achando que algum estivesse trocado mas todos sĆo iguais.

    Inclusive um outro erro que dava no inicio foi corrigido, array[i,j]
    tem a aloca‡Ćo invertida na mem˘ria (do Delphi em rela‡Ćo ao VBA ou
    Fortran) e precisou indicar como array[j,i].

    Algu‚m tem id‚ia do que pode causar esse erro e como corrigir?

    Abaixo estĆo as declara‡äes da rotina, tipos e chamada no VBA e no
    Delphi:

    -----------------------------------8<-----------------------------------
    Option Explicit

    Declare Sub SISOPT Lib "c:\SISOPT\SisOpt8.DLL" _
    (iModel As Long, iLP As Long, Iy1 As Long, iM1 As Long, m As Long, n
    As Long, _
    Ny As Long, Nnd As Long, _
    Ndns As Long, Nname As Long, PT As Double, _
    R1max As Double, TC As Double, FC As Double, Smin As Double, R1min
    As Double, _
    Smax As Double, cst As Double, Xini As Double, dm As Double, Y As
    Double, _
    Sum As Double, SSum As Double, PSP As Double, FPRT As Double, _
    PRT As Double, SV As Double, _
    Wt1 As Double, Wt2 As Double, Wt3 As Double, Wt4 As Double, Wt5 As
    Double, Wt6 As Double, _
    iFun As Long, Tg As Double, TotS As Double, ierr As Long, Fobj As
    Double, _
    iEnding As Long, Xend As Double, _
    delta As Double, nite As Long, epsSLP As Double, epsILP As Double,
    RUNTIME As Double, _
    EN2 As Double, EC As Double, PRICE As Double, IRIVER As Long,
    SRIVER As Double, _
    EVP As Double, EV_LP As Double, AC As Double)

    Sub RunEmn()
    ' (...)

    Dim i As Long, j As Integer, k As Integer, l As Integer, _
    R As Integer, CC As Integer, Nmonth As Integer, kk As Integer, _
    iModel As Long, iLP As Long
    Dim Var1 As Variant, Var2 As Variant
    Dim Iy1 As Long, m As Long, n As Long, Ny As Long, Nnd As Long
    Dim iM1 As Long, NStep As Long
    Dim Infeas As Long
    Dim Ndns(1 To 150) As Long
    Dim Nname(1 To 150) As Long
    Dim PT(1 To 4, 1 To 150) As Double
    Dim Fd(1 To 2, 1 To 150) As Double
    Dim R1max(1 To 150) As Double
    Dim TC(1 To 150) As Double
    Dim FC(1 To 150, 1 To 12) As Double
    Dim Smin(1 To 150) As Double
    Dim R1min(1 To 150) As Double
    Dim cst(1 To 2, 1 To 150) As Double
    Dim Xini(1 To 150) As Double
    Dim Smax(1 To 150) As Double
    Dim dm(1 To 20, 1 To 12) As Double
    Dim fEnergy As Double
    Dim Y(1 To 120000) As Double
    Dim Sum(1 To 240) As Double
    Dim SSum(1 To 150, 1 To 240) As Double
    Dim ierr As Long, iTail As Long
    Dim T As Double, T1 As Double, T2 As Double
    Dim iFun As Long, Tg(1 To 150, 1 To 12) As Double, TotS(1 To 20, 1 To
    12) As Double
    Dim anote(1 To 100) As String, A As String
    Dim PSP(1 To 150) As Double, Hdel(1 To 150) As Double, _
    FPRT(1 To 4, 1 To 5, 1 To 150) As Double, PRT(1 To 150, 1 To 20, 1
    To 12) As Double
    Dim iSV As Long, SV(1 To 150) As Double, Fobj As Double, SS As Double
    Dim Wt1 As Double, Wt2 As Double, Wt3 As Double, Wt4 As Double, Wt5 As Double, Wt6 As Double
    Dim varBefore As Date, varAfter As Date, varTimeDiff As Date
    Dim iEnding As Long, iSystem As Integer, iSys As Integer, Xend(1 To
    150) As Double
    Dim delta As Double, nite As Long, epsSLP As Double, epsILP As Double, RUNTIME As Double
    Dim EN2 As Double, EC As Double, PRICE(1 To 12) As Double, IRIVER As
    Long, SRIVER As Double
    Dim EVP(1 To 150, 1 To 12) As Double, AC(1 To 150, 1 To 12) As Double
    Dim nTC(1 To 150) As Integer, EV_LP(1 To 150) As Double
    Dim USI As String * 3
    Const ForReading = 1, ForWriting = 2
    Dim fso, f
    (...)
    Call SISOPT _
    (iModel, iLP, Iy1, iM1, m, n, Ny, Nnd, Ndns(1), Nname(1), PT(1, 1), _
    R1max(1), TC(1), FC(1, 1), Smin(1), R1min(1), _
    Smax(1), cst(1, 1), Xini(1), dm(1, 1), Y(1), _
    Sum(1), SSum(1, 1), PSP(1), FPRT(1, 1, 1), PRT(1, 1, 1), _
    SV(1), _
    Wt1, Wt2, Wt3, Wt4, Wt5, Wt6, _
    iFun, Tg(1, 1), TotS(1, 1), ierr, Fobj, iEnding, Xend(1), _
    delta, nite, epsSLP, epsILP, RUNTIME, _
    EN2, EC, PRICE(1), IRIVER, SRIVER, EVP(1, 1), EV_LP(1), AC(1, 1)) -----------------------------------8<-----------------------------------
    type vl150=array[1..150] of longint;
    vd150x4=array[1..150, 1..4] of double;
    vd150x2=array[1..150, 1..2] of double;
    vd150=array[1..150] of double;
    vd150x12=array[1..150, 1..12] of double;
    vd12x150=array[1..12, 1..150] of double;
    vd12x20=array[1..12, 1..20] of double;
    vd120k=array[1..120000] of double;
    vd240=array[1..240] of double;
    vd240x150=array[1..240, 1..150] of double;
    vd150x5x4=array[1..150, 1..5, 1..4] of double;
    vd12x20x150=array[1..12, 1..20, 1..150] of double;
    vd12=array[1..12] of double;

    procedure SISOPT(var iModel, iLP, Iy1, iM1, m, n, Ny, Nnd: longint; var
    Ndns, Nname: vl150; var PT: vd150x4; var R1max, TC: vd150; var FC:
    vd12x150; var Smin, R1min, Smax: vd150; var cst: vd150x2; var Xini:
    vd150; var dm: vd12x20; var Y: vd120k; var Sum: vd240; var SSum:
    vd240x150; var PSP: vd150; var FPRT: vd150x5x4; var PRT: vd12x20x150;
    var SV: vd150; var Wt1, Wt2, Wt3, Wt4, Wt5, Wt6: double; var iFun:
    longint; var Tg: vd12x150; var TotS: vd12x20; var ierr: longint; var
    Fobj: double; var iEnding: longint; var Xend: vd150; var delta: double;
    var nite: longint; var epsSLP, epsILP, RUNTIME, EN2, EC: double; var
    PRICE: vd12; var IRIVER: longint; var SRIVER: double; var EVP: vd12x150;
    var EV_LP: vd150; var AC: vd12x150); stdcall; external 'sisopt8.dll';

    (...)

    SISOPT(iModel, iLP, Iy1, iM1, m, n, Ny, Nnd, Ndns, Nname, PT, R1max, TC,
    FC, Smin, R1min, Smax, cst, Xini, dm, Y, Sum, SSum, PSP, FPRT, PRT, SV,
    Wt1, Wt2, Wt3, Wt4, Wt5, Wt6, iFun, Tg, TotS, ierr, Fobj, iEnding, Xend,
    delta, nite, epsSLP, epsILP, RUNTIME, EN2, EC, PRICE, IRIVER, SRIVER,
    EVP, EV_LP, AC); -----------------------------------8<-----------------------------------

    []s
    ---
    ţ QMPro 1.51 ţ If u cn rd ths, u cn gt a gd jb on cmptr prgrmmng.

    ---
    # Origin: telnet hidrasoft.dyndns.org 55-11-4654-2024 SP,Brasil (4:801/161)
    * Origin: LiveWire BBS - Synchronet - LiveWireBBS.com (1:2320/100)