Autor Beitrag
pepsen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Do 23.11.06 09:35 
hey leute...
kann ich einem Projekt eine weitere Unit hinzufügen? Was hab ich da zu beachten! Bitte so einfach wie möglich beschreiben...Schritt für Schritt, wenns geht!
Wie kann ich außerdem die in der neuen Unit geschriebenen Proceduren aufrufen?

mfg Pepsen
Reinhard Kern
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 591
Erhaltene Danke: 14



BeitragVerfasst: Do 23.11.06 10:29 
user profile iconpepsen hat folgendes geschrieben:
hey leute...
kann ich einem Projekt eine weitere Unit hinzufügen? Was hab ich da zu beachten! Bitte so einfach wie möglich beschreiben...Schritt für Schritt, wenns geht!
Wie kann ich außerdem die in der neuen Unit geschriebenen Proceduren aufrufen?

mfg Pepsen


Hallo,

einfach Datei -> neu -> Unit. Dann als erstes im Unit-Fenster Speichern unter (die neue Unit heisst erst mal Unit1 o.ä) und der Unit einen sinnvollen Namen geben wie VectorMath für Vektor-Berechnungen.

Um die Prozeduren (bzw. irgendwas sonst wie Typen, Variablen) zu benutzen, muss die Unit unter "uses" aufgeführt werden. Man kann also durchaus auch Units nur mit Typdefinitionen anlegen, oder nur mit Konstanten.

Gruss Reinhard
pepsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Do 23.11.06 10:40 
fein, danke dir! Ich werd mein Glück erstmal versuchen! Bei weiteren Probs werd ich dann wieder schrein ^^
pepsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Fr 24.11.06 08:50 
so nun doch noch was...und zwar hab ich eine neue Unit erstellt, diese auch in die "hauptunit" in den uses eingebunden! Nur, wie kann ich da jetzt auf die Prozeduren der eingebundenen Unit zugreifen?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 24.11.06 09:30 
Wie auf die internen Funktionen. Aber das geht natürlich nur mit Funktionen, die im Interface deklariert sind.

_________________
Markus Kinzler.
pepsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Fr 24.11.06 10:12 
heißt es also, dass es mit Prozeduren gar nich möglich ist?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 24.11.06 10:15 
user profile iconpepsen hat folgendes geschrieben:
heißt es also, dass es mit Prozeduren gar nich möglich ist?

Doch es geht mit Funktionen und Proceduren, diese müßen aber im Interface bekannt gegeben werden (Deklarationen der Signaturen).

_________________
Markus Kinzler.
pepsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Fr 24.11.06 10:16 
ah ok, danke =D da werd ich mal mein Glück versuchen ;o)
pepsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Fr 24.11.06 11:04 
jetzt bekomm ich die Fehlermeldung:

Ungenügende Forward- oder External-Deklaration :?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 24.11.06 11:43 
Zeige mal den Code, der diesen Fehler verursacht.

_________________
Markus Kinzler.
pepsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Fr 24.11.06 12:49 
ausblenden Delphi-Quelltext
1:
procedure leseMaxLnr ();					


das hab ich halt im Interface stehn um diese Prozedur aus der Unit "Sondertage" aufzurufen
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 24.11.06 13:03 
Du hast was mißverstanden, die Unit muß im Interface der Unit stehen, in der sie implmentiert wird also in Sondertage.

_________________
Markus Kinzler.
pepsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Mo 27.11.06 09:47 
hmmm... also ich hab die neue Unit jetzt in den USES der Hauptunit stehn...wenn ich allerdings die Prozeduren aufrufen will, wird mir gesagt, dass es ein "undefinierter Bezeichner" ist.
wahrscheinlich is da meine Syntax einfach falsch...ein Beispiel würd mir da wohl weiterhelfen
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 27.11.06 09:56 
Hier mal ein Minimalbeispiel, wie es geht:

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

interface

uses dialogs;

// Deklaration der Prozedur, damit sie auch außerhalb bekannt ist
procedure Sagwas;

implementation

// Implementierung der Prozedur
procedure Sagwas;
begin
  ShowMessage('Was');
end;

end.


Code der Hauptunit, ein Button auf dem Formular mit zugewiesenem OnClick-Event:
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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, unit2;
  // hier wird die andere Unit eingebunden

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  // das ist die Prozedur aus Unit2
  sagwas;
end;

end.

Wenn man jetzt auf den Button klickt, sollte das Pogramm was sagen. ;-)

_________________
We are, we were and will not be.
pepsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Mo 27.11.06 10:09 
:(
das hab ich genauso und es funktioniert nich!
NTM
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 120

Win XP
2005 Prof
BeitragVerfasst: Mo 27.11.06 10:13 
Schreibe unter dem Feld implementation uses und dort deine unit rein dann sollte es gehen. z.b. uses unit2;
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 27.11.06 10:13 
Das kann nicht sein. Irgendwas muss anders sein. Hast du evtl. die Prozedur (bei mir "sagwas") auch in der Hauptunit deklariert (was nicht sein darf)?

_________________
We are, we were and will not be.
pepsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Mo 27.11.06 10:26 
nee, den Fehler hatte ich vorher mal gemacht...da kam dann auch die Fehlermeldung: "Ungenügende Forward- oder External-Deklaration"
ich hatte auch eben mal noch einen Uses-Teil in die Implementation gepackt und die Unit dort aufgerufen! Funktioniert allerdings auch nicht!

muss ich vllt die Prozedur über die Form aufrufen? also so: Form1.Prozedur;?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 27.11.06 10:30 
Poste am besten mal deinen kompletten Code (Also beide Units). Irgendwo ist da ne Kleinigkeit falsch, und das Rumgerate bringt ja nix.

_________________
We are, we were and will not be.
pepsen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 51



BeitragVerfasst: Mo 27.11.06 10:46 
Ich hab das ein wenig abgespeckt, weil es sonst zu lang und unübersichtlich gewesen wäre! Ich hoffe, dass es trotzdem reichen wird!

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

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, Grids, ValEdit, StdCtrls, DB, DBTables, ExtCtrls, Maxlnr;

type
    TForm1 = class(TForm)
    ComboBoxFG: TComboBox;
    Query1: TQuery;
    DataSource1: TDataSource;
    StringGrid1: TStringGrid;
    EditFT: TEdit;
    Label1: TLabel;
    ButtonHinzu: TButton;
    DateTimeVon: TDateTimePicker;
    DateTimeBis: TDateTimePicker;
    CheckBoxMehrtag: TCheckBox;
    GroupBoxFT: TGroupBox;
    CBAll: TCheckBox;
    ButtonErweitern: TButton;
    ComboBoxErweitern: TComboBox;
    
    procedure HinZuAll ();

  private
  { Private-Deklarationen }

  public
  { Public-Deklarationen }
  
  
end;

var
  Form1: TForm1;

implementation
  
{$R *.dfm}



procedure TForm1.HinZuAll;
var FGAuswahl, sql: string;
    DateVon, DateBis: double;
    lnr: Integer;
begin
  DateVon := trunc(DateTimeVon.Date + 693594);
  DateBis := trunc(DateTimeBis.Date + 693594);
  sql := Format ('SELECT * FROM Z4MSYS WHERE F1=%s', [QuotedStr (FGAuswahl)]);
  query1.Close;
  query1.SQL.Clear;
  query1.SQL.Add(sql);
  query1.Open;
  lnr := query1.FieldByName('LNR').asinteger;
  leseMaxLnr;
  query1.SQL.Clear;
  query1.SQL.add('SELECT * FROM Z4MSYS');
  query1.Open;
  query1.Append;
  query1.FieldByName('LNR').AsString := IntToStr((StrToInt(maxlnr) + 1));
  query1.FieldByName('F3').AsString := editFT.Text;
  query1.FieldByName('F1').AsString := FloatToStr(DateVon);
  query1.FieldByName('F6').AsString := '';
  query1.FieldByName('ART').AsString := 'SO';
  query1.FieldByName('NR').AsString := '0';
  if CheckBoxMehrtag.Checked = True then query1.FieldByName('F2').AsString := FloatToStr(DateBis);
  query1.Post;
  schreibeausDB;
end;

end.


Unit Maxlnr
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:
unit Maxlnr;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, Grids, ValEdit, StdCtrls, DB, DBTables, ExtCtrls;

type
    procedure leseMaxLnr;

end;


implementation

procedure leseMaxLnr;
begin
  query1.SQL.Clear;
  query1.SQL.Add('SELECT * FROM Z4MSYS WHERE LNR=(SELECT MAX(LNR) FROM Z4MSYS)');
  query1.RequestLive := true;
  query1.Open;
  maxlnr := query1.FieldByName('LNR').AsString;
  query1.Close;
end;


end.