Autor Beitrag
Gerhard_S
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98



BeitragVerfasst: Fr 09.08.13 21:48 
Hallo,
meine Unit1 fängt so an
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, StdCtrls, Forms,
  Dialogs, Menus, ExtCtrls, Unit2, Unit3, Unit4, Unit5, Unit6, Unit7, Unit8, Unit9,
  Unit10, Unit11, Unit13, Unit14, Unit15 {usw. usf.}
type
  TForm1 = class(TForm)
  {...}
  function CheckDates(newyear, newmonth, newday: string): Boolean;

In meiner Unit2 steht
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, Mask, StdCtrls, FileCtrl, ComCtrls, DateUtils;
type
  TFrame2 = class(TFrame)
{usw. usf.}
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;
implementation

{$R *.dfm}
uses Unit1;

Wenn ich jetzt aus Unit2 eine Funktion in Unit1 ansprechen will, muss ich vor den Namen der Funktion immer die Form schreiben, z.B.
ausblenden Delphi-Quelltext
1:
if Form1.CheckDates(Parameter1, Parameter2, Parameter3) then {...}					

Das wundert mich, denn bisher hat Delphi XE2 allein durch Einbindung von Unit1 die Funktion CheckDates gekannt. Kann es sein, dass die explizite Einbindung der Form irgendwo in den Projektoptionen verlangt wird?

Moderiert von user profile iconMartok: Code- durch Delphi-Tags ersetzt
Hidden
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2242
Erhaltene Danke: 55

Win10
VS Code, Delphi 2010 Prof.
BeitragVerfasst: Fr 09.08.13 22:11 
Hallo Gerhard,

du hast CheckDates als Methode der Formularklasse TForm1 deklariert. Das bedeutet, jedes Objekt dieser Klasse hat diese Methode und der Aufruf kann auf alle Feldvariablen des Objekts zugreifen.

Damit das möglich ist, musst du angeben auf welches Objekt du dich beziehst (es könnte ja auch jemand mehrere Formulare vom Typ TForm1 erzeugen und parallel anzeigen).
Innerhalb einer Objekt-Methode existiert ein globaler Kontext self, der das Objekt enthält das diese Methode gerade aufruft. Tippst du hier ein CheckDates;, so wird versucht diese Methode im aktuellen Kontext zu parsen; der Aufruf entspricht dann einem self.CheckDates;.

Grüße,
Daniel

PS: Wenn du Statt [code]-Tags [delphi]-Tags verwendest, bekommen deine Quelltexte das gewohnte Delphi-highlighting :)

_________________
Centaur spears can block many spells, but no one tries to block if they see that the spell is a certain shade of green. For this purpose it is useful to know some green stunning hexes. (HPMoR)