Thema: Delphi Klassen in DLL

Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#14

Re: Klassen in DLL

  Alt 21. Sep 2008, 14:45
Dann zeig mal ein Beispiel...
Nur Interesse halber hier ist meins ..
Extra klein VB mit Delphi formatiert hehhehehe...
"Form Main"
Delphi-Quellcode:
Option Explicit

Dim objPerson As IPerson

Private Sub Create_Click()
    On Error Resume Next

    objPerson = Nothing
    Set objPerson = CreatePerson(cmbPerson.ListIndex)
    objPerson.GebDatum = CDate(Text1.Text)
    objPerson.Name = Text2.Text

    objPerson.Sprich
End Sub

Private Sub Form_Load()
    cmbPerson.AddItem "Baby"
    cmbPerson.AddItem "Student"
    cmbPerson.ListIndex = 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set objPerson = Nothing
End Sub
"Bas"
Delphi-Quellcode:
Option Explicit

Public Enum PersonType
   Baby = 0
   Student = 1
End Enum

Public Function CreatePerson(ByVal ptPerson As PersonType) As IPerson
                                 
    Select Case ptPerson
        Case Baby
            Dim objBaby As cBaby
            Set objBaby = New cBaby
            objBaby.WindelVoll
            Set CreatePerson = objBaby
        Case Student
            Dim objStudent As cStudent
            Set objStudent = New cStudent
            objStudent.Betrunken
            Set CreatePerson = objStudent
    End Select
    
End Function
Exe Fertig !

Die Interface Schnittstelle person ..
"Class"
Delphi-Quellcode:
Option Explicit

Public Property Let GebDatum(ByVal dNew As Date)
End Property

Public Property Get GebDatum() As Date
End Property

Public Property Let Name(ByVal sNew As String)
End Property

Public Property Get Name() As String
End Property

Public Function Sprich() As String
End Function
fertig.
Nun das Baby
Delphi-Quellcode:
Option Explicit

Implements IPerson

Private md_GebDate As Date
Private ms_Name As String

Private Sub Class_Initialize()
    MsgBox "Baby geboren"
End Sub

Private Sub Class_Terminate()
    MsgBox "Baby 'zerstört' ;)"
End Sub

Private Property Get IPerson_GebDatum() As Date
    IPerson_GebDatum = md_GebDate
End Property

Private Property Let IPerson_GebDatum(ByVal RHS As Date)
    md_GebDate = RHS
End Property

Private Property Let IPerson_Name(ByVal RHS As String)
    ms_Name = RHS
End Property

Private Property Get IPerson_Name() As String
    IPerson_Name = ms_Name
End Property

Private Function IPerson_Sprich() As String
    MsgBox "Ich heisse " & ms_Name & " und bin am " & md_GebDate & " geboren worden"
End Function

//zur Demonstration, das diese Klasse die Vererbten Methoden und Attribute
//beinhaltet, aber auch spezifische Sachen, nur die Klasse betreffend
Public Function WindelVoll()
    MsgBox "Meine Windel is voll. Bitte einmal wechseln"
End Function
Baby als Plugin fertig
Student
Delphi-Quellcode:
Option Explicit

Implements IPerson

Private md_GebDate As Date
Private ms_Name As String

Private Sub Class_Initialize()
    MsgBox "An der Uni eingeschrieben"
End Sub

Private Sub Class_Terminate()
    MsgBox "Verdammt. Schon wieder rausgeflogen"
End Sub

Private Property Get IPerson_GebDatum() As Date
    IPerson_GebDatum = md_GebDate
End Property

Private Property Let IPerson_GebDatum(ByVal RHS As Date)
    md_GebDate = RHS
End Property

Private Property Let IPerson_Name(ByVal RHS As String)
    ms_Name = RHS
End Property

Private Property Get IPerson_Name() As String
    IPerson_Name = ms_Name
End Property

Private Function IPerson_Sprich() As String
    MsgBox "Ich heisse " & ms_Name & " und bin am " & md_GebDate & " geboren worden"
End Function

//zur Demonstration, das diese Klasse die Vererbten Methoden und Attribute
//beinhaltet, aber auch spezifische Sachen, nur die Klasse betreffend
Public Function Betrunken()
    MsgBox "Boah war die letzte Party übel. Ich glaub ich kotz gleich"
End Function
fertig ...
Jetzt mach das in Delphi ein komplettes Interface mit Plugin support...
Ich behaupte das du mehr an Aufwand betreiben mußt und es so einfach in Delphi nicht geht !!!

gruss Emil
Angehängte Dateien
Dateityp: rar interfaces_beispiel_122.rar (22,3 KB, 7x aufgerufen)
  Mit Zitat antworten Zitat