Autor Beitrag
Airtrox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109


Delphi 7
BeitragVerfasst: Fr 18.12.09 19:33 
Hallo,

ich habe 3 Units (Unit2 ist die Hauptunit), welche ich passend verknüfen will, wobei ich dachte, dass ich es auch hätte, aber anscheinend unit3 nicht auf unit1 zugreifen kann. In unit1 ist eine Procedur, welche ich in unit3 abrufen will. Aber seht selbst.

Unit2:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
uses unit1, unit3, ...

...

implementation


{$R *.dfm}


Unit1:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
uses ...

...

implementation

uses unit2, unit3;

{$R *.dfm}


Unit3:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
unit Unit3;

interface

uses unit1

...

implementation

{$R *.dfm}

uses unit2;

Eigentlich müssten so doch alle Units aufeinander zugreifen können?


Moderiert von user profile iconNarses: Topic aus VCL (Visual Component Library) verschoben am Fr 18.12.2009 um 23:39
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Fr 18.12.09 19:35 
Ich glaube, dass ist nicht so wie in C/C++.
Du musst für jede Unit die Units einbinden, da gibts keine art von Kapselung oder Vererbung..
Bin mir aber nicht sicher!
glotzer
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 393
Erhaltene Danke: 49

Win 7
Lazarus
BeitragVerfasst: Fr 18.12.09 19:39 
am einfachsten wäre wohl alles was du in in den beiden units brauchst in nen unit 4 zu packen...
Airtrox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109


Delphi 7
BeitragVerfasst: Fr 18.12.09 19:48 
an Niko:
Es sind eigentlich alle miteinader verknüpft, entweder stehen die anderen unit oben oder unten in der uses.
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Fr 18.12.09 19:56 
Oh stimmt, entschuldigung, hab ich irgendwie nicht ganz gerafft.
Vielleicht liegts dann einfach nur an den Bezeichnungen? ^^
Oder die procedure ist in "Private" deklariert? Passiert mir auch manchmal..
Airtrox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109


Delphi 7
BeitragVerfasst: Fr 18.12.09 20:42 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
...
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

uses unit2;


So siehts bei unit 3 aus.
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Fr 18.12.09 20:53 
Und die procedure steht im private teil? Oder ist das gar nichts drin?
Weil ich seh da nichts, wo Form1 da zugreifen könnte.

Das wäre dann ja "Form3.Procedure;"..
Airtrox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109


Delphi 7
BeitragVerfasst: Fr 18.12.09 21:04 
Ich kann dir nicht ganz folgen: Die aufzurufende Prozedur steht in unit1 gleich hinter {$R *.dfm}
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Fr 18.12.09 21:43 
mach sie doch noch im "public" teil rein
also
ausblenden Delphi-Quelltext
1:
2:
3:
Public
  procedure IrgendeineProcedure(var: Integer);
[...]
Airtrox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109


Delphi 7
BeitragVerfasst: Fr 18.12.09 21:59 
gebe ich das in der unit an, in der sich die procedur befindet, kommt folgende fehlermeldung:

[Fehler] Unit1.pas(58): Ungenügende Forward- oder External-Deklaration: 'TForm1.meineprocedur'
Die Procedur benötigt keine variabeln, also meineprocedur()
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Fr 18.12.09 22:05 
Kannst du mal den Code posten O:
Airtrox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109


Delphi 7
BeitragVerfasst: Fr 18.12.09 23:15 
also den code der unit1 (gekürzt):

ausblenden 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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ...;

type
  TForm1 = class(TForm)
  ...
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    procedure meinstring();
  end;

implementation

uses unit2, unit3;

{$R *.dfm}

procedure meinstring();
begin
...
end;
Niko S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 566
Erhaltene Danke: 10

Win 7, Ubuntu
Lazarus, Turbo Delphi, Delphu 7 PE
BeitragVerfasst: Fr 18.12.09 23:23 
ausblenden 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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ...;

type
  TForm1 = class(TForm)
  ...
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    procedure meinstring();
  end;

implementation

uses unit2, unit3;

{$R *.dfm}

procedure TForm1.meinstring();
begin
...
end;
Airtrox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109


Delphi 7
BeitragVerfasst: Fr 18.12.09 23:41 
Vielen Dank! Es klappt :)