Autor Beitrag
ggehrma
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

WinXP
D2005 Pers.
BeitragVerfasst: Mi 29.06.05 17:39 
Hallo,

Ich möchte eine Array-Variable, die ich in meinem Hauptformular definiert habe auch an meine Nebenformulare weitergeben. Geht das irgendwie? Wenn nicht, wie kann ich mein Problem dann lösen? Das Array einfach im Public-Teil des Hauptformulars zu definieren funktioniert leider nicht. Im Nebenformular kann ich dann leider trotzdem nicht auf das Array zugreifen.

Danke.
mfg, ggehrma
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mi 29.06.05 17:45 
Sollte gehen. Du musst das array dann so aufrufen:
ausblenden Delphi-Quelltext
1:
 x := MainForm.testarray[1]					
ggehrma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

WinXP
D2005 Pers.
BeitragVerfasst: Mi 29.06.05 17:49 
Und genau das funktioniert nicht. Hab ich nämlich schon längst ausprobiert.
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mi 29.06.05 17:52 
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:
    procedure BTKlicken(Sender: TObject);
    procedure BXKlicken(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }


   bt : array[1..100of TBitBtn;
   bx : array[1..20of TGroupBox;

   BTExst: array[1..100of boolean;
   BXExst: array[1..20of boolean;
   BTPreis: array[1..100of currency; 
   BTshct: array[1..100of string;     
   BTVsbl: array[1..100of boolean;   
   
  end;         
var
  Form2: TForm2;

implementation

uses Unit1, Unit4, Unit3, Unit10;

{$R *.dfm}


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
if Form2.BTshct[hbt] = '' then
          begin
          
          end
          else
          begin
          Form2.bt[hbt].Caption := '&'+Form2.btshct[hbt]+': '+Form2.bt[hbt].Caption;
          end;


funzt bei mir enwandfrei. WElche D version verwendest du?
ggehrma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

WinXP
D2005 Pers.
BeitragVerfasst: Mi 29.06.05 21:39 
verwende D7.0 Enterprise
ggehrma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

WinXP
D2005 Pers.
BeitragVerfasst: Do 30.06.05 14:38 
Hm, okay. Habe grade gemerkt, dass ich die Array-Werte aus dem Hauptformular zwar vom Nebenformular aus verändern kann, aber sie dort nicht auslesen kann. Genau das muss ich aber machen.

Bitte helft mir.

mfg, ggehrma
ManuelGS
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 173

Win XP HE, Suse Linux
D6, D7, D2005 Personal
BeitragVerfasst: Do 30.06.05 14:51 
du erstellst deine arrays vom hauptformular einfach als globale variablen, d.h. vor dem implementation-teil.
im nebenformular dann im implementation-teil "uses form1". jetzt kannst du die variable normalerweise <global> in beiden formularen benutzen.

bsp:

unit2: (Nebenform.)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
var
  Form2: TForm2;
  hans:integer;

implementation

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
begin
hans:=3;
end;



unit1: (Hauptform.)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
implementation

uses unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(inttostr(hans));   //3
hans:=5;
showmessage(inttostr(hans));   //5
end;

_________________
"Leben ist gänzlich Bühne und Spiel; so lerne denn spielen
und entsage dem Ernst - oder erdulde das Leid." - Palladas von Alexandria
ggehrma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

WinXP
D2005 Pers.
BeitragVerfasst: Do 30.06.05 16:53 
Problem hat sich erledigt. Fehler lag woanders dran. Trotzdem danke für die vielen Antworten.

mfg, ggehrma
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Do 30.06.05 17:05 
Wo denn?
ggehrma Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 111

WinXP
D2005 Pers.
BeitragVerfasst: Do 30.06.05 17:09 
Hatte fälschlicher Weise mein Nebenformular mit dem Ereignis OnCreate statt OnShow aufgerufen. Dadurch wurde natürlich der Code des Nebenformulars schon vor dem eigentlichen Aufruf abgearbeitet und nicht dann, wann er eigentlich sollte.