Link to home
Start Free TrialLog in
Avatar of negone
negone

asked on

Class in VB DLL

VB can send classes as parameters in their dll's.  What I need to do is to access a class that is in a VB dll.  I have the source code to the VB dll but can not change it as I am not in charge of the dll and other applications use it.
Avatar of TheNeil
TheNeil

Can you create an equivalent class in Delphi (matching the structure byte for byte) and then try to pass that?

An alternative might be to use Variants

The Neil
Avatar of negone

ASKER

I have to access the class that was written in VB.  If I didn't have to do that, I would just write it in Delphi and forget about the VB code.
If you have the source, can you show us the VB structure of the class.

I think that you have misunderstood what 'The Neil' means. He is not suggesting that you rewrite the whole dll in Delphi, but just mimic the structure of the class that you are interested in.

Surely if you need to access this class parameter, you would need to do this anyway.

Aubs
Avatar of negone

ASKER

I am not sure what the order of the methods and members are but here is the source.

////////////////////////////////////////
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsFluid"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit


Private Name As String
Private No As Integer
Private Cat As String   'lower case flucat for increased comparison safety
Private FluCat As String
Private LiqGas As Boolean
Private CC As Single
Private Pres As Single
Private MaxCC As Single
Private MinCC As Single
Private MaxFPoint As Single
Private MinFPoint As Single
Private TempMin As Single
Private TempMax As Single
Private ENo As Integer
Private VVisc(1 To 3) As Single
Private VCP(1 To 3) As Single
Private VCond(1 To 3) As Single
Private VLat(1 To 3) As Single
Private VPres(1 To 3) As Single
Private Wmol As Single
Private Tcr As Single
Private Pcr As Single
Private LVisc(1 To 3) As Single
Private LDens(1 To 3) As Single
Private LCP(1 To 3) As Single
Private LCond(1 To 3) As Single
Private FreezePoint As Single
Private Brinematrix(1 To 18, 1 To 11) As Single  'Brine matrix

Public Sub CreateFluid(Fname As String, DBPath As String)
Dim FluidDb As Database
Dim AllRst As Recordset
Dim FluidRst As Recordset
Dim BrineRst As Recordset
Dim ReferencesRst As Recordset
   
Dim j As Byte
Dim i As Integer
    'Initialize or reset Fluid variables
    Name = "": Cat = "": FluCat = "": LiqGas = False
    No = 0: CC = 0:   Pres = 0: MaxCC = 0: MinCC = 0: MaxFPoint = 0: MinFPoint = 0
    TempMin = 0: TempMax = 0: ENo = 0: Wmol = 0: Tcr = 0: Pcr = 0: FreezePoint = 0
    Erase VVisc, VCP, VCond, VLat, VPres, LVisc, LDens, LCP, LCond, Brinematrix
    'Set new values
    Set FluidDb = Workspaces(0).OpenDatabase(DBPath, False)
    Set AllRst = FluidDb.OpenRecordset("SELECT * FROM FluidInfo WHERE Name='" & Fname & "'", dbOpenSnapshot)
    Name = AllRst.Fields("CallName").Value
    FluCat = AllRst.Fields("Category").Value
    Cat = LCase(FluCat)
    With FluidDb
        Set FluidRst = .OpenRecordset("SELECT * FROM GetFluid WHERE CallName='" & Name & "'", dbOpenSnapshot)
        Set ReferencesRst = .OpenRecordset("SELECT * FROM Limits WHERE CallName='" & Name & "'", dbOpenSnapshot)
        Set BrineRst = .OpenRecordset("SELECT * FROM Concentration WHERE Concentration.Name = '" & Name & "'", dbOpenSnapshot)
    End With
    If Cat = "liqconc" Or Cat = "oldbrine" Then
        No = FluidRst.Fields("Nr").Value
        Wmol = 0
        Tcr = 0
        Pcr = 0
        'FreezePoint = FluidRst.Fields("FP").Value
        Call Limitset(Name, 0, TempMax, TempMin, MaxCC, MinCC)
        Set FluidDb = Nothing: Exit Sub
    ElseIf Cat <> "brine" Then
        TempMin = FluidRst.Fields("Tmin").Value
        TempMax = FluidRst.Fields("Tmax").Value
        ENo = FluidRst.Fields("EkvNr").Value
        Wmol = FluidRst.Fields("Wmol").Value
        Tcr = FluidRst.Fields("Tcrit").Value
        Pcr = FluidRst.Fields("Pcrit").Value
        No = FluidRst.Fields("Nr").Value
        FreezePoint = FluidRst.Fields("FP").Value
        For j = 1 To 3
            VVisc(j) = FluidRst.Fields("VapVisc" & j).Value
            VCP(j) = FluidRst.Fields("VapCP" & j).Value
            VCond(j) = FluidRst.Fields("VapCond" & j).Value
            VLat(j) = FluidRst.Fields("VapLat" & j).Value
            VPres(j) = FluidRst.Fields("VapPres" & j).Value
            LVisc(j) = FluidRst.Fields("LiqVisc" & j).Value
            LDens(j) = FluidRst.Fields("LiqDens" & j).Value
            LCP(j) = FluidRst.Fields("LiqCP" & j).Value
            LCond(j) = FluidRst.Fields("LiqCond" & j).Value
        Next j
    Else
        With ReferencesRst
            MaxCC = .Fields("ConcMax").Value
            MinCC = .Fields("ConcMin").Value
            MaxFPoint = .Fields("TfreezeMax").Value
            TempMax = .Fields("TempMax").Value
            MinFPoint = .Fields("TfreezeMin").Value
            Wmol = 0
            Tcr = 273.15
            'Pcr = 0
        End With
 
        With BrineRst
            .MoveFirst
            Brinematrix(1, 9) = .Fields("xmc").Value
            Brinematrix(1, 10) = .Fields("xmf").Value
            Brinematrix(1, 11) = .Fields("ym").Value
            For i = 1 To 18
                Brinematrix(i, 1) = .Fields("i").Value
                Brinematrix(i, 2) = .Fields("j").Value
                Brinematrix(i, 3) = .Fields("Freeze").Value
                Brinematrix(i, 4) = .Fields("Conc").Value
                Brinematrix(i, 5) = .Fields("Density").Value
                Brinematrix(i, 6) = .Fields("Specificheat").Value
                Brinematrix(i, 7) = .Fields("T_Conductivity").Value
                Brinematrix(i, 8) = .Fields("Viscosity").Value
                .MoveNext
            Next i
        End With
    End If
    Set FluidDb = Nothing
End Sub

Public Function FP_from_Conc(ByVal Temp As Single) As Single
Dim field1 As Byte, field2 As Byte
    field1 = 9: field2 = 3
    FP_from_Conc = Result(Brinematrix, field1, field2, CC, Temp)
End Function

Public Function Conc_from_FP(ByVal Temp As Single) As Single
Dim field1 As Byte, field2 As Byte
    field1 = 10: field2 = 4
    Conc_from_FP = Result(Brinematrix, field1, field2, FreezePoint, Temp)
End Function

'According to Redlich-Kwong
Public Function CompFactor(ByVal Temp As Single) As Single
Const THIRD = 1 / 3
Dim Ta As Single
Dim x(3)
Dim z As Single
Dim a As Single
Dim q As Single
Dim R As Single
Dim b As Single
Dim j As Integer
Dim Tci As Single
Dim Pci As Single
Dim Pressure As Single
    Pressure = Pres / 1000
    Temp = Temp + 273.15
    Tci = Tcr
    Pci = Pcr
    Ta = Temp
    z = 1
    If Abs(Tci - 273.15) > 0.0001 Then
        a = Sqr(0.4278 * (Tci / Ta) ^ 2.5 / Pci)
        b = 0.08664 * Tci / Pci / Ta
        q = b * Pressure * (a ^ 2 / b - b * Pressure - 1)
        R = -a ^ 2 / b * (b * Pressure) ^ 2 + q / 3 - 0.0740741
        q = q - THIRD
        z = R ^ 2 / 4 + q ^ 3 / 27
        If z < 0 Then
            a = Sign(1, -R) * Sqr(-6.75 * R ^ 2 / q ^ 3)
            If a >= 1 Then R = 0 Else R = ArcCos(a) / 3
            a = -100
            For j = 1 To 3
                x(j) = Cos(R + 2.094395 * (j - 1))
                If x(j) > a Then a = x(j)
            Next j
            z = THIRD + 2 * Sqr(-q / 3) * a
        Else
            a = Sqr(z)
            b = -R / 2
            q = b + a
            R = b - a
            z = THIRD + Sign(1, q) * Abs(q) ^ THIRD + Sign(1, R) * Abs(R) ^ THIRD
        End If
    End If
    If z > 1 Then z = 1
    CompFactor = z
End Function

Public Function Density(ByVal Temp As Single) As Single
Dim cd1 As Single
Dim cd2 As Single
Dim cd3 As Single
Dim EkvNr As Integer
Dim z As Single
Dim field1 As Byte, field2 As Byte
    If Cat = "liqconc" Or Cat = "oldbrine" Then
        Call DensitConstantSet(Name, Temp, CC, EkvNr, cd1, cd2, cd3)
    ElseIf Cat = "brine" Then
        field1 = 9: field2 = 5
        EkvNr = 2000
    Else
        If Cat = "vap" Or ((Cat = "liqvap" Or Cat = "oldref") And LiqGas) Then
            z = CompFactor(Temp)
            EkvNr = 1000
        Else
            cd1 = LDens(1)
            cd2 = LDens(2)
            cd3 = LDens(3)
            EkvNr = ENo
        End If
    End If
    Select Case EkvNr
    Case 0, 1
        Density = cd1 + Temp * (cd2 + Temp * cd3)
    Case 2
        Density = cd1 + Temp * (cd2 + Temp * cd3)
        Density = Exp(Density) * 1000
    Case 100
        Density = cd1
    Case 1000
        Density = Pres / 1000 * Wmol / z / 8.3143 / (Temp + 273.15)
    Case 2000
        Density = Result(Brinematrix, field1, field2, CC, Temp)
    End Select
End Function

Public Function LatHeat(ByVal Temp As Single) As Single
Dim cLat1 As Single
Dim cLat2 As Single
Dim cLat3 As Single
     cLat1 = VLat(1)
     cLat2 = VLat(2)
     cLat3 = VLat(3)
        If Temp < cLat2 Then
        LatHeat = cLat1 * (cLat2 - Temp) ^ cLat3
    End If
    LatHeat = LatHeat * 1000
End Function

Public Function Viscosity(ByVal Temp As Single) As Single
Dim x As Single
Dim cv1 As Single
Dim cv2 As Single
Dim cv3 As Single
Dim Dens As Single
Dim EkvNr As Integer
Dim field1 As Byte, field2 As Byte
    If Cat = "liqconc" Or Cat = "oldbrine" Then
        If CallName = "Pekasol_50" Then Dens = Density(Temp)
        Call ViscConstantSet(Name, Temp, CC, Dens, EkvNr, cv1, cv2, cv3)
    ElseIf Cat = "brine" Then
        field1 = 9: field2 = 8
        EkvNr = 2000
    Else
        If (Cat = "vap") Or ((Cat = "liqvap" Or Cat = "oldref") And LiqGas) Then
            EkvNr = 1000
            cv1 = VVisc(1)
            cv2 = VVisc(2)
            cv3 = VVisc(3)
        Else
            EkvNr = ENo
            cv1 = LVisc(1)
            cv2 = LVisc(2)
            cv3 = LVisc(3)
        End If
    End If
    Select Case EkvNr
    Case 0
        x = cv2 * Temp
        Viscosity = cv1 * Exp(x)
    Case 1
        x = cv2 / (cv3 + Temp)
        Viscosity = cv1 * Exp(x)
    Case 2
        Viscosity = cv1 * Exp(cv2 / (cv3 + Temp))
    Case 100
        Viscosity = cv1
    Case 1000
        Viscosity = cv1 + cv2 * Temp + cv3 * Temp ^ 2
    Case 2000
        Viscosity = Exp(Result(Brinematrix, field1, field2, CC, Temp))
    End Select
    Viscosity = Viscosity / 1000
End Function

Public Function Conductivity(ByVal Temp As Single) As Single
Dim cc1 As Single
Dim cc2 As Single
Dim cc3 As Single
Dim EkvNr As Integer
Dim field1 As Byte, field2 As Byte
    If Cat = "liqconc" Or Cat = "oldbrine" Then
        Call CondConstantSet(Name, Temp, CC, EkvNr, cc1, cc2, cc3)
    ElseIf Cat = "brine" Then
        field1 = 9: field2 = 7
        EkvNr = 2000
    Else
        If Cat = "vap" Or ((Cat = "liqvap" Or Cat = "oldref") And LiqGas) Then
            cc1 = VapCond(1)
            cc2 = VapCond(2)
            cc3 = VapCond(3)
            EkvNr = 1000
        Else
            cc1 = LiqCond(1)
            cc2 = LiqCond(2)
            cc3 = LiqCond(3)
            EkvNr = ENo
        End If
    End If
    Select Case EkvNr
    Case 0, 1
        Conductivity = cc1 + Temp * (cc2 + Temp * cc3)
    Case 2
        Conductivity = cc1 + Temp * (cc2 + Temp * cc3)
        Conductivity = Conductivity + 0.0000000283594 * Temp ^ 3
    Case 100
        Conductivity = cc1
    Case 1000
        Conductivity = cc1 + cc2 * Temp + cc3 * Temp ^ 2
    Case 2000
        Conductivity = Result(Brinematrix, field1, field2, CC, Temp)
    End Select
End Function

Public Function CP(ByVal Temp As Single) As Single
Dim ccp1 As Single
Dim ccp2 As Single
Dim ccp3 As Single
Dim EkvNr As Integer
Dim Pr As Single
Dim Tr As Single
Dim XCp As Single
Dim Fe As Single
Dim FTc As Single
Dim field1 As Byte, field2 As Byte
    If Cat = "liqconc" Or Cat = "oldbrine" Then
        Call CpConstantSet(Name, Temp, CC, EkvNr, ccp1, ccp2, ccp3)
    ElseIf Cat = "brine" Then
        field1 = 9: field2 = 6
        EkvNr = 2000
    Else
        If Cat = "vap" Or ((Cat = "liqvap" Or Cat = "oldref") And LiqGas) Then
            ccp1 = VCP(1)
            ccp2 = VCP(2)
            ccp3 = VCP(3)
            EkvNr = 1000
        Else
            ccp1 = LCP(1)
            ccp2 = LCP(2)
            ccp3 = LCP(3)
            EkvNr = ENo
        End If
    End If
    Select Case EkvNr
    Case 0, 1
        CP = ccp1 + Temp * (ccp2 + Temp * ccp3)
    Case 2
        CP = ccp1 + Temp * (ccp2 + Temp * ccp3)
        CP = CP + (-0.00000144769 + 0.00000007354465 * CC - 0.000000000811462 * CC ^ 2 + 2.26045E-12 * CC ^ 3) * Temp ^ 3
        CP = Exp(CP) * 4.1868
    Case 3
        CP = ccp1 + Temp * (ccp2 + Temp * ccp3)
        CP = Exp(CP) * 4.1868
    Case 100
        CP = ccp1
    Case 1000   'Gas Timo's change
        Pr = Pres / 1000
        XCp = ccp1 + Temp * (ccp2 + Temp * ccp3)
        If Pr <= 100 Then
            CP = XCp
        Else
            Pr = Pr / Pcr
            Tr = (Temp + 273.15) / Tcr
            If Tr > 1.01 Then
                FTc = Exp(-8.088 + 6.718 * Tr)
            Else
                FTc = 10.134 - 9.126 * Tr
                Tr = Exp(-0.35206 + 13.673 * Pr - 20.078 * Pr ^ 2 + 13.084 * Pr ^ 3) * FTc
                Fe = Exp(2.02124 + 3.9113 * Pr - 2.1987 * Pr ^ 2 + 2.6387 * Pr ^ 3)
            End If
            If Tr > Fe Then Tr = Fe
            CP = XCp + Tr / Wmol
        End If
        Case 2000
            CP = Result(Brinematrix, field1, field2, CC, Temp) / 1000
    End Select
    CP = CP * 1000
End Function

Public Sub Limits(ConcMax As Single, ConcMin As Single, Tmax As Single, Tmin As Single, MaxFreeze As Single, MinFreeze As Single)
Dim field1 As Byte, field2 As Byte
    If Cat = "liqconc" Or Cat = "oldbrine" Then
        Call Limitset(Name, CC, Tmax, Tmin, ConcMax, ConcMin)
    ElseIf Cat = "brine" Then
        ConcMax = MaxCC
        ConcMin = MinCC
        MaxFreeze = MaxFPoint
        MinFreeze = MinFPoint
        Tmax = TempMax
        If CC = 0 Then
            Tmin = TempMin
        Else
            TempMin = FP_from_Conc(0)
        End If
    Else
        Tmax = TempMax
        Tmin = TempMin
    End If
End Sub

Public Function VapPressure(ByVal Temp As Single) As Single
Dim cpr1 As Single
Dim cpr2 As Single
Dim cpr3 As Single
Dim tmparr As Variant
    cpr1 = VPres(1)
    cpr2 = VPres(2)
    cpr3 = VPres(3)
    VapPressure = (Exp(cpr1 + cpr2 / (Temp + cpr3))) * 1000
End Function

Public Property Get CallName() As String
    CallName = Name
End Property

Public Property Get Category() As String
    Category = FluCat
End Property

Public Property Get Tmin() As Single
    Tmin = TempMin
End Property

Public Property Get Tmax() As Single
    Tmax = TempMax
End Property

Public Property Get MaxConc() As Single
    MaxConc = MaxCC
End Property

Public Property Get MinConc() As Single
    MinConc = MinCC
End Property

Public Property Get MaxFP() As Single
    MaxFP = MaxFPoint
End Property

Public Property Get MinFP() As Single
    MinFP = MinFPoint
End Property

Public Property Get EqvNo() As Integer
    EqvNo = ENo
End Property

Public Property Get VapVisc() As Variant
    VapVisc = VVisc
End Property

Public Property Get VapCP() As Variant
    VapCP = VCP
End Property

Public Property Get VapCond() As Variant
    VapCond = VCond
End Property

Public Property Get VapLat() As Variant
    VapLat = VLat
End Property

Public Property Get VapPres() As Variant
    VapPres = VPres
End Property

Public Property Get FluidWmol() As Single
    FluidWmol = Wmol
End Property

Public Property Get Tcrit() As Single
    Tcrit = Tcr
End Property

Public Property Get LiqDens() As Variant
    LiqDens = LDens
End Property

Public Property Get LiqVisc() As Variant
    LiqVisc = LVisc
End Property

Public Property Get LiqCP() As Variant
    LiqCP = LCP
End Property

Public Property Get LiqCond() As Variant
    LiqCond = LCond
End Property

Public Property Get Pcrit() As Single
    Pcrit = Pcr
End Property

Public Property Get Pressure() As Single
    Pressure = Pres
End Property

Public Property Let Pressure(ByVal NewPres As Single)
    Pres = NewPres
End Property

Public Property Get Conc() As Single
    Conc = CC
End Property

Public Property Let Conc(ByVal NewCC As Single)
Dim dummy As Single
    CC = NewCC
    If Cat = "brine" Then
        FreezePoint = FP_from_Conc(0)
        TempMin = FreezePoint
    ElseIf Cat = "liqconc" Or Cat = "oldbrine" Then
        Call Limits(dummy, dummy, dummy, FreezePoint, dummy, dummy)
        TempMin = FreezePoint
    End If
End Property

Public Property Get Gas() As Boolean
    Gas = LiqGas
End Property

Public Property Let Gas(ByVal NewLiqGas As Boolean)
    LiqGas = NewLiqGas
End Property

Public Property Get matrix() As Variant
    matrix = Brinematrix
End Property

Public Property Get FP() As Single
    FP = FreezePoint
End Property

Public Property Let FP(ByVal NewFP As Single)
    FreezePoint = NewFP
    If Cat = "brine" Then CC = Conc_from_FP(0)
End Property

Public Property Get Number() As Integer
    Number = No
End Property

ASKER CERTIFIED SOLUTION
Avatar of Epsylon
Epsylon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of negone

ASKER

How do I use it once i have it in the ImportType Library?
Avatar of negone

ASKER

You knew what I was looking for even if I didn't.
Does this mean that it works now?
Avatar of negone

ASKER

I am sure it will.  I got it to link and generate the file.  I just have a lot to code to write before I can test it very well