Autor Beitrag
mimi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Fr 18.07.03 17:56 
Hallo,
ich habe ein C++ Header und will ihn in delphi übersetztn leider weiß ich nicht genau wie das geht, der c++ header ist für ne dll die in c++ geschrieben werden soll, die klasse sieht so aus:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
//1. Datei
// pacbasicki.h
#ifndef PACBASICKI_H
#define PACBASICKI_H

// BOOL-Type
typedef enum { TRUE = 0, FALSE } BOOL;

// point-type
typedef struct pacPoint
{
    int x,y;
    pacPoint operator+ (pacPoint p1)
    {
        pacPoint p2;
        p2.x = x+p1.x;
        p2.y = y+p1.y;
        return p2;
    }

    pacPoint operator- (pacPoint p1)
    {
        pacPoint p2;
        p2.x = x-p1.x;
        p2.y = y-p1.y;
        return p2;
    }

} PAC_POINT;

// map-type
typedef int** PAC_MAP;

// direction-types
typedef enum { PAC_DIRNONE = 0, PAC_DIRLEFT, PAC_DIRRIGHT, PAC_DIRUP, PAC_DIRDOWN } PAC_DIR;
const PAC_POINT PAC_DIRS[5] = { { 0, 0 }{-1, 0 }{ 1, 0 }{ 0,-1 }{ 0, 1 } };

// PacMan's basic AI
typedef class pacBasicKI
{
  public:
    // class constructor
    pacBasicKI(PAC_POINT p, PAC_MAP m, BOOL e = FALSE);
    // class destructor
    virtual ~pacBasicKI();
    // Let's GO!
    void Run (int steps);
    // to change/get some data
        void Enabled (BOOL e) { _enabled = e; }
;
    BOOL Enabled (void) const { return _enabled; };
    void Position (PAC_POINT p) { _position = p; };
    PAC_POINT Position (void) const { return _position; };
    protected:
        // find your way
        BOOL IsFree (PAC_DIR d);
    private:
        // is the AI enabled?
        BOOL _enabled;
        // the game map
        PAC_MAP _map;
        // the actual position
        PAC_POINT _position;
        // find your way
        virtual PAC_DIR Walking (PAC_DIR d = PAC_DIRNONE);
} PAC_BASIC_KI, * PPAC_BASIC_KI;

#endif // PACBASICKI_H


//2. date
// pacfollowingki.h
#ifndef PACFOLLOWINGKI_H
#define PACFOLLOWINGKI_H
 
#include "pacbasicki.h" // inheriting class's header file
 
// PacMan's intelligent AI
typedef class pacFollowingKI : public pacBasicKI
{
    public:
        // class constructor
        pacFollowingKI(PAC_POINT p, PAC_MAP m, BOOL e = FALSE);
        // class destructor
        ~pacFollowingKI();
    private:
        // find your way
        PAC_DIR Walking (PAC_DIR d = PAC_DIRNONE);
}
 PAC_FOLLOW_KI, * PPAC_FOLLOW_KI;

#endif // PACFOLLOWINGKI_H

währe sehr hilfreich, wenn ihr mir tips geben könntet oder sowas, gibt es dafür vileicht auch schon tools ?

_________________
MFG
Michael Springwald, "kann kein englisch...."
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Fr 18.07.03 18:34 
Man kann keine Klassen in Delphi importieren. BCB kann auch keine VC++ Klassen importieren. Das hängt mit dem ABI (Application Binary Interface) zusammen.

_________________
Ist Zeit wirklich Geld?
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Fr 18.07.03 20:39 
wie muss die klasse aussehen wenn es ein Delphi Header sein soll ?

_________________
MFG
Michael Springwald, "kann kein englisch...."
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Sa 19.07.03 00:30 
Wie soll ich das vertehen? Einen "Delphi-Header" gibt es nicht. Möchtest du jetzt die C++ Klasse umbauen? Das wird auch nichts bringen, da es an der gemeinsamen ABI scheitert. Du könntest aber Interfaces einsetzen. Diese haben einen vorgegebene Aufbau und es sind durch die Interface-VMT auch keine mangled names aus der DLL zu lesen. Nachteil ist, dass du die "Klassen" nicht ableiten kannst.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
{$MINENUMSIZE 4}
{$ALIGN 4} // kann aber auch 1 oder 8 sein. Das hängt vom C++ Compiler ab
type
  TDeleteMode = (dmStackBased = 2, dmHeapBased = 3);

// PacMan's basic AI 
pacBasicKI = object
public
  // class constructor 
   procedure Init(p: PAC_POINT; m: PAC_MAP; e: Bool = False); cdecl;
  // class destructor 
   procedure Done(DeleteMode: TDeleteMode = dmStackBased); virtualcdecl;
  // Let's GO! 
   procedure Run(Steps: Integer); cdecl;
  // to change/get some data 
   procedure Enabled(e: Bool); overload{inline}
   function Enabled: Bool; overload{inline}
   procedure Position(p: PAC_POINT); overload{inline} 
   function Position: PAC_POINT; overload{inline}
protected
  // find your way 
   function IsFree(d: PAC_DIR): Bool; cdecl;
private
  // is the AI enabled? 
  _enabled:  BOOL; 
  // the game map 
  _map: PAC_MAP; 
  // the actual position 
  _position: PAC_POINT; 
  // find your way 
  function Walking(d: PAC_DIR = PAC_DIRNONE): PAC_DIR; virtualcdecl
end;
PAC_BASIC_KI = pacBasicKI;
PPAC_BASIC_KI = ^pacBasicKI;


procedure pacBasicKI.Init; external MyLib name '10pacBasicKI';
procedure pacBasicKI.Done; external MyLib name '_10pacBasicKI';
procedure pacBasicKI.Run; external MyLib name 'Run_10pacBasicKIi';
function pacBasicKI.IsFree;  external MyLib name 'IsFree_10pacBasicKI7PAC_DIR';
function pacBasicKI.Walking; external MyLib name 'Walking_10pacBasicKI7PAC_DIR';

procedure pacBasicKI.Enabled(e: Bool); overload{inline}
begin
  _enabled := e;
end;

function pacBasicKI.Enabled: Bool; overload{inline}
begin
  Result := _enabled;
end;

procedure pacBasicKI.Position(p: PAC_POINT); overload{inline}
begin
  _position := p;
end;

function pacBasicKI.Position: PAC_POINT; overload{inline}
begin
  Result := _position; 
end;


Ob das funktionieren wird ist fraglich, denn die mangled names habe ich vom Linux gcc 2.95 genommen und der hat eine andere ABI als BCB oder VC++.

_________________
Ist Zeit wirklich Geld?
mimi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3458

Ubuntu, Win XP
Lazarus
BeitragVerfasst: Sa 19.07.03 12:52 
werde ich mal testen, danke:)

_________________
MFG
Michael Springwald, "kann kein englisch...."