Autor Beitrag
seppel86
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54



BeitragVerfasst: Sa 07.02.04 16:22 
Hi,
ich hab folgendes Problem. In meinem Programm benutze ich 2 Units. Die Prozeduren aus unit2 muss ich in unit1 verwenden, also hab ich in unit1 stehen uses unit2.
In unit2 sind die Proceduren in der Klasse TForm1 gespeichert.
Wenn ich die Prozedur X nun folgendermaßen in unit1 aufrufe:

unit2.TForm1.X(...); kriege ich folgenden Fehler: This form of method call only allowed for class methods.

Was mach ich falsch?
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Sa 07.02.04 16:32 
ausblenden Delphi-Quelltext
1:
unit2.Form1.X(...);					


Das "T" ist zuviel... :wink:
seppel86 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54



BeitragVerfasst: Sa 07.02.04 16:39 
Hab ich auch schon probiert. Der fragt mich dann, ob er uses unit1 in die unit1 hinzufügen soll, wenn ichs mach sagt er dass sich die Unit nicht selbst benutzen kann, wenn nicht kompiliert er nicht.
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Sa 07.02.04 16:42 
Hast Du in unit2 unit1 auch drin stehen ?

Dann schreib das uses unit2 mal in unit1 unterhalb von implementation nicht direkt oben..
seppel86 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54



BeitragVerfasst: Sa 07.02.04 16:46 
da hab ichs auch stehen. wenn ichs unters interface reinsetze erkennt er das X aus der Prozedur als undeklarierte Variable an.
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Sa 07.02.04 16:49 
Poste mal die beiden Unitköpfe inkl. TForm1...
seppel86 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54



BeitragVerfasst: Sa 07.02.04 16:52 
Das ist Unit1:

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

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button1: TButton;
    StringGrid1: TStringGrid;
    Image1:TImage;
    Label4: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  xglobal,yglobal,b :Integer;

  a:array [1..9of Integer;
  spieler1,spieler2 :String;
implementation

uses unit2, Unit1;



Das ist Unit2

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
unit Unit2;

interface uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Grids;

  type Tform1 = class(TForm)
  image1:TImage;
  StringGrid1:TStringGrid;



  procedure Kreis(Sender: TObject);
  procedure X(Sender: TObject);
  procedure Spieler1Win(Sender: TObject);
  procedure Spieler2Win(Sender: TObject);
  end;


die Prozeduren selbst brauch ich nicht posten,oder?

Moderiert von user profile iconPeter Lustig: Delphi-Tags hinzugefügt
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Sa 07.02.04 17:00 
Zitat:

implementation

uses unit2, Unit1;


Was ist das ?. Wieso "benutzt" Du Unit1 in Unit1 ??
seppel86 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54



BeitragVerfasst: Sa 07.02.04 17:02 
hab ich oben erklärt. wenn ich unit2.form1.X schreibe weill der die automatisch da reinsetzen (funzt natürlich nicht). Mir ist klar das das da nix zu suchen hat.
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Sa 07.02.04 17:14 
Zuerst einmal kann man in einem Projekt nicht zwei Formulare mit dem gleichen Namen haben. Ändere also einen ab..

Dann muss dieses uses Unit1 raus...

Dann solltest Du diese Prozedur X im Public von TFormxx deklarieren, weil man sonst nicht drauf zugreifen kann...
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Sa 07.02.04 17:14 
So wird es nicht funktionieren.

Die Formulare der beiden Units heißen gleich! Das geht in einem Projekt aber nicht. Also eins umbenennen und dann erstmal unit1 und unit2 komplett aus den uses löschen. Dann den Aufruf so gestalten:form1.X(...);Also das Unit1 weglassen.
Dann Kompilieren jetzt auf ja drücken, wen er fragt, ob er die Unit in die uses schreiben soll. Sollte funktionieren.

[edit]Mist. Wide rmal zu spät![/edit]

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
seppel86 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54



BeitragVerfasst: Sa 07.02.04 17:29 
Funzt auch nicht. Das macht absolut keinen unterschied.
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Sa 07.02.04 20:11 
Zitat:
Dann solltest Du diese Prozedur X im Public von TFormxx deklarieren, weil man sonst nicht drauf zugreifen kann...
Hast du das schon gemacht?
Also:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
  type Tform1 = class(TForm) 
  image1:TImage; 
  StringGrid1:TStringGrid; 
  {...}
  private
  {...}
  public
  procedure Kreis(Sender: TObject); 
  procedure X(Sender: TObject); 
  procedure Spieler1Win(Sender: TObject); 
  procedure Spieler2Win(Sender: TObject); 
  {...}
  end;


mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)