Autor Beitrag
error
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Mo 17.02.03 12:08 
Hi,
ich möchte eine Variable haben die von 2 Forms gleichzeitig benutzt wird. Das heisst wenn die Variable in Form2 geändert wird, soll sie in Form1 auch geändert worden sein.

thx i a - error
foxy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 814

Ubuntu, Gentoo
C++, PHP, Java, Ruby, Perl (Eclipse)
BeitragVerfasst: Mo 17.02.03 12:10 
einfach eine globale variable deklarieren. Natürlich in deiner Mainfrm....

_________________
"Only wimps use tape backup: real men just upload their important stuff on ftp, and let the rest of the world mirror it." (Linus Torvalds)
OperatingSystem Laptop (Ubuntu Hardy)
error Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Mo 17.02.03 12:11 
Das hatte ich mir schon gedacht :)
Die Frage ist WIE ich sowas mache...
foxy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 814

Ubuntu, Gentoo
C++, PHP, Java, Ruby, Perl (Eclipse)
BeitragVerfasst: Mo 17.02.03 12:14 
:lol:
kkk
also soweit ich mich noch erinnern kann ( da ich dieses nie benutze, wegen unübersichtlichkeit), musst du über der implementation also unter public diese Deklarieren

ausblenden Quelltext
1:
2:
3:
Public
procedure xxx;
var variable1;

_________________
"Only wimps use tape backup: real men just upload their important stuff on ftp, and let the rest of the world mirror it." (Linus Torvalds)
OperatingSystem Laptop (Ubuntu Hardy)
error Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Mo 17.02.03 12:19 
foxy hat folgendes geschrieben:
:lol:
kkk
also soweit ich mich noch erinnern kann ( da ich dieses nie benutze, wegen unübersichtlichkeit), musst du über der implementation also unter public diese Deklarieren

ausblenden Quelltext
1:
2:
3:
Public
procedure xxx;
var variable1;


Entweder ich lass das 'var' weg, dann ist die Variable in der anderen Form nicht deklariert, oder ich schreibs mit hin, dann funktionierts gar net mehr...
Popov
Gast
Erhaltene Danke: 1



BeitragVerfasst: Mo 17.02.03 12:23 
Variable im Interface Teil vereinbaren und die Unit im zweiten Formular unter Uses anmelden.
foxy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 814

Ubuntu, Gentoo
C++, PHP, Java, Ruby, Perl (Eclipse)
BeitragVerfasst: Mo 17.02.03 12:33 
Popov das ist noch der Interfaceteil oder etwa nicht??? der geht wohl bis zu Imple...
und das man die Unit1 in der anderen in die Uses setzten muss iss wohl klar :twisted:

_________________
"Only wimps use tape backup: real men just upload their important stuff on ftp, and let the rest of the world mirror it." (Linus Torvalds)
OperatingSystem Laptop (Ubuntu Hardy)
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 17.02.03 13:07 
foxy hat folgendes geschrieben:
musst du über der implementation also unter public diese Deklarieren

Im Implementationsteil gibt es keine Public-Sektion. So eine Sektion befindet sind zum Beispiel in der Form-Deklaration.

foxy hat folgendes geschrieben:
und das man die Unit1 in der anderen in die Uses setzten muss iss wohl klar

Warum ist das klar?

Gruß
TINO
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 17.02.03 13:30 
@error:Ich wollte nur mal drauf hinweisen, dass zwölf Threads unter Deinem dieser Beitrag zu finden ist!

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
BungeeBug
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 901



BeitragVerfasst: Mo 17.02.03 13:47 
also so gehts jetzt genau ....
ausblenden 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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations } <- Hier muss die Variable eingebunden werden!!!
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin

end;

end.
foxy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 814

Ubuntu, Gentoo
C++, PHP, Java, Ruby, Perl (Eclipse)
BeitragVerfasst: Mo 17.02.03 13:52 
BungeeBug hat folgendes geschrieben:
also so gehts jetzt genau ....
Code:

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

interface 

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

type 
  TForm1 = class(TForm) 
    procedure FormCreate(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } <- Hier muss die Variable eingebunden werden!!! 
  end; 

var 
  Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.FormCreate(Sender: TObject); 
begin 

end; 

end.


hmmm ich denke nicht das dies geht ... das kannst du mit functionen oder proceduren machen aber nich mit variabeln

ausblenden Quelltext
1:
2:
3:
4:
5:
Public
prcedure xx;
function xxx;
end;
var variable: DWORD;

sry habe oben das end; vergessen

und
@tino

Lesen Pls
ich habe geschrieben "über" d.h. das dies wohl nicht der Implement.teil ist aber egal :wink2:

_________________
"Only wimps use tape backup: real men just upload their important stuff on ftp, and let the rest of the world mirror it." (Linus Torvalds)
OperatingSystem Laptop (Ubuntu Hardy)
Wolff68
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 302
Erhaltene Danke: 1

WinXP home
D6 Prof
BeitragVerfasst: Mi 19.02.03 19:43 
Mal ausführlich:
Unit1 mit Form1:
ausblenden volle Höhe 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:
...
type
  TForm1 = class(TForm)
    Edit1: TEdit;
  private
    { Private-Deklarationen }
    PrivatVariable : String; <= OHNE var, und VOR Prozeduren oder Funktionen.
    function PrivatFunktion : String;
  public
    { Public-Deklarationen }
    PublicVariable : String; <= OHNE var, und VOR Prozeduren oder Funktionen.
    function PublicFunktion : String;
  end;

function GlobalFunktion : String;

var
  Form1: TForm1;
  GlobalVariable : String;

implementation
{$R *.dfm}

function GlobalFunktion : String;
begin
  Result := 'Bla';
end;

{ TForm1 }
function TForm1.PrivatFunktion : String;
begin
  Result := 'Bla';
end;

function TForm1.PublicFunktion : String;
begin
  Result := 'Bla';
end;
...

Unit2 mit Form2
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
...
implementation

uses Unit1; // Notwendig !!!

{$R *.dfm}

procedure TForm2.FormActivate(Sender: TObject);
begin
  Label1.Caption := Form1.Edit1.Text;
  Label2.Caption := Form1.PublicVariable;
  Label3.Caption := Form1.PublicFunktion;
  Label4.Caption := GlobalVariable;
  Label5.Caption := GlobalFunktion;
  // Zugriff auf PrivatVariable nicht möglich
  // Zugriff auf PrivatFunktion nicht möglich
end;
...

Man beachte, daß PrivateVariable/Funktion und PublicVariable/Function Unterelemente von Form1 sind. GlobalVariable/Function ist ohne Form1. anzusprechen. Auch sind die Komponenten unter Form1 quasi Public, und somit ebenfalls von 'aussen' ansprechbar (Edit1)

_________________
"Der Mensch ist nicht was er sich vorstellt oder wünscht zu sein, sondern das was andere in ihm sehen."