Autor Beitrag
smilie128
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 48



BeitragVerfasst: Sa 24.01.04 15:52 
Hi Leute!

Folgendes Problem:
Ich möchte eine Komponente Erzeugen in der prozeduren und Funktionen aus einer externen DLL verwendet werden,
Wie z.B. procedure PortOut(xyz :qwe); StdCall; External;
In einem normalen Programm habe ich damit auch kein Problem.
Wenn ich aber versuche eine Komponente zu installieren, in der zum Beispiel die oben genannte Procedure und ein paar eigene verwendet werden dann bekommen ich im späteren Programm nur meine eigenen Proceduren und Funktionen zur Verfügung gestellt.
Lange Rede kurzer Sinn: An welcher Stelle des Codes meiner Komponente muß ich eine Deklaration wie oben geschrieben einbinden?

Ach ja ich benutze Delphi 6 Enterprise.

Mfg
smilie128

Moderiert von user profile iconMotzi: Code- durch Delphi-Tags ersetzt


Zuletzt bearbeitet von smilie128 am Mo 26.01.04 13:12, insgesamt 1-mal bearbeitet
TomT
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 116

Suse 9.1 WinXP
D6 Pers
BeitragVerfasst: So 25.01.04 17:15 
Im public-Bereich. Da du diese Methode ja veröffentlichen willst:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
type
  MeineKlasse = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
    procedure PortOut(xyz :qwe); StdCall; External;
  end;

_________________
...und da wurde mir klar, dass eine Toolbar keine Kneipe für Heimwerker ist.
smilie128 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 48



BeitragVerfasst: So 25.01.04 17:51 
Hi !

In meiner Ausgangsfrage fehlte noch 'io.dll' am Ende der Prozedure.
Also ich habe jetzt folgendes probiert:
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:
unit MeineKomponente;

interface

uses
  Windows, Messages, SysUtils, Classes,ExtCtrls;

type
  MeineKlasse = class(TComponent)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
  // #### Hierum gehts ! ################

    procedure PortOut(Port : Word; Data : Byte);StdCall;External 'io.dll'; 

  //###############################
  published
    { Published declarations }
  end;

procedure Register;

implementation


procedure Register;
begin
  RegisterComponents('Samples', [MeineKlasse]);
end;

end.

Bei dieser Methode bekomme ich beim installieren der komponente dei fehlermeldungen:

    [Error] MeineKomponente.pas(16): Field definition not allowed after methods or properties
    [Error] MeineKomponente.pas(19): ',' or ':' expected but 'END' found
    [Error] MeineKomponente.pas(16): Unsatisfied forward or external declaration: 'MeineKlasse.PortOut'
    [Fatal Error] dclusr.dpk(37): Could not compile used unit 'test\MeineKomponente.pas'

Ich habe auch schon versucht die Prozedure nach 'implementation' einzufügen. Das Ergebnis habe ich oben beschrieben.

Vielleicht mache ich ja irgendeinen dummen Denkfehler.

Mfg
smilie128

Moderiert von user profile iconMotzi: Code- durch Delphi-Tags ersetzt.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 26.01.04 09:20 
Je nachdem ob der Import nur innerhalb der Unit verwendbar sein soll oder auch nach außen hin sichtbar deklariert man ihn entweder im Inferface- oder im Implementations-Abschnitt, aber niemals in einer Klassendeklaration..!

Also so (nach außen sichtbar):
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:
unit MeineKomponente; 

interface 

uses 
  Windows, Messages, SysUtils, Classes,ExtCtrls; 

type 
  MeineKlasse = class(TComponent) 
  private 
    { Private declarations } 
  protected 
    { Protected declarations } 
  public 
    { Public declarations } 
  published 
    { Published declarations } 
  end; 

procedure PortOut(Port : Word; Data : Byte);StdCall;External 'io.dll'; // <--

procedure Register; 

implementation 


procedure Register; 
begin 
  RegisterComponents('Samples', [MeineKlasse]); 
end; 

end.


Oder so (nur innerhalb der Unit verwendbar):
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:
unit MeineKomponente; 

interface 

uses 
  Windows, Messages, SysUtils, Classes,ExtCtrls; 

type 
  MeineKlasse = class(TComponent) 
  private 
    { Private declarations } 
  protected 
    { Protected declarations } 
  public 
    { Public declarations } 
  published 
    { Published declarations } 
  end; 

procedure Register; 

implementation 

procedure PortOut(Port : Word; Data : Byte);StdCall;External 'io.dll'; // <--

procedure Register; 
begin 
  RegisterComponents('Samples', [MeineKlasse]); 
end; 

end.

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
smilie128 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 48



BeitragVerfasst: Mo 26.01.04 13:10 
Danke Motzi,

ich hatte es nicht am Ende des Interface-Teils versucht weil ich dachte,
das ich die Abschnitte public oder published benutzen muß, wenn die Funktion oder Prozedur außerhalb genutzt werden soll.

Besten Dank für den Tipp

@TomT
Sorry ich hatte mich glaube ich in meiner Frage falsch ausgedrückt.

Gruß
smilie128