Autor Beitrag
FloL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Win XP
Delphi 2005
BeitragVerfasst: Mo 31.10.05 01:46 
Hi, kann mir mal einer sagen, wie ich eine Variabel von unit2 in unit1 benutzen kann? Kann ich die variabel in unit1 auch benutzen, wenn ich unit2 schon geschlossen habe?
Wie kann ich hier eigentlich mein code hier zur schau stellen?
Ich habe jetzt die variabel unter public deklariert in unit1 und in unit2, da ich auf die variabel in beiden units zugreifen möchte. Allerdings in unit2 funktioniert das, aber in unit1 geht das leider nicht. Muss ich wie bei ediffeldern, etc.. "unit1.Form2.edit1.text" so schreiben? Sprich "unit2.Form2.x", aber so funktioniert das auch nicht......
Ist wahrscheinlch ganz einffach, aber habe mit Delphi, mal kurz in meiner Schulzeit zu tuen gehabt, so 1 Jahr lang und das ist auch schon gute 6 Jahre her und gestern hab ich mal wieder angefangen mit Delphi zu programmieren. Meistens hab ich bis jetzt in Excel programmiert... Geht auch irgendwie einfacher ;)
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Mo 31.10.05 09:42 
Ich komm nicht so richtig mit was du meinst aber wenn ich mich richtig entsinne gibt es ein Problem wenn du Probierst Units doppelt zu verzahnen da das unsauber ist.

Du musst die Unit1 der UNit 2 bekannt geben und ggF. dem Projekt hinzufügen falls sie in einem anderen Pfad liegt.

Du könntest die Variable auch per VAR übergeben so das innerhalb einer Prozedur nicht eine neue temporäre Variable angelegt wird sondern die Variable bei Veränderungen auch verändert wird.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mo 31.10.05 09:45 
Hallo !

Die Variable kommt nach Public wie Du schon sagtest.
In deiner Hauptform musst Du die zweite Form mit angeben und umgekehrt.

implementation

uses Unit2;

Zugreifen kannst Du dann über Form2.Meine_Variable:=True;
auch wenn das Fenster geschlossen ist.
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mo 31.10.05 09:46 
Du must die Unit2 in die uses von der Unit1 machen:
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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;
{$R *.DFM}


end.
FloL Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Win XP
Delphi 2005
BeitragVerfasst: Mo 31.10.05 12:05 
Hi, danke hat geklappt.
Mischel24NRW
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Mo 14.11.05 19:04 
Ich möchte eine Variable sowohl in Unit 1 als auch in Unit 3 verwenden. Seh ich das richtig, dass ich das in Unit1 so deklarieren muss:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
  public
    { Public declarations }
  Helferanzahl: integer;
  Helfernamen: tinifile;
  end;

var
  Form1: TForm1;
  d:  integer;
  
  implementation

uses Unit2;
uses unit3;


und dann in unit 3 so verwenden kann:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
  public
    { Public declarations }
  end;



var
  Form3: TForm3;
  Form1.helferanzahl:=True;
  Form1.Helfernamen:=True;

uses Unit1;



Denn irgendwie funktioniert das net! Kommt in Unit3 ne Fehlermeldung...

Kann mir da jemand bei helfen?


Danke schonmal...
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 14.11.05 23:31 
ausblenden Delphi-Quelltext
1:
2:
Form1.helferanzahl := True;  
Form1.Helfernamen := True;

Das hier muss wo anders hin (z.B. in OnShow, etc.).

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Mischel24NRW
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Mo 14.11.05 23:46 
Jetzt gääht er :-)

Vielen Dank!
Green
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

Windows XP Home
Delphi 6 Enterprise
BeitragVerfasst: Mo 14.11.05 23:49 
und du kannst das zweite uses unter implantation weglassen.

also:

ausblenden Delphi-Quelltext
1:
2:
3:
  implementation

uses Unit2,Unit3;


wie bei Var. Da schreibst du au nit

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var zahl1:integer;
var zahl2: integer;
var string1:string

//sondern

var zahl1,zahl2:integer;
    string1:string;