Autor Beitrag
littlemike1005
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187



BeitragVerfasst: So 19.10.03 00:10 
Hhllo

wer kann mir sagen wie ich eine Variable xxx (string) der ich in form1 einen string z.B. "hallo welt" zuweise in form2 weiter verwenden kann und diese aber weiter ihren inhalt "hallo welt" führt.

kurz den inhalt einer variable von form1 mit nach form2 nehmen.

danke.
Ja-Pa
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 458

Win XP, Suse 9.3
D1, D3, D5 Std, D7 Pro, D2005 Pers, Kylix 3
BeitragVerfasst: So 19.10.03 10:39 
In Form2 muss zuerst die Unit von Form1 (z.B. Unit1) in die uses-Liste aufgenommen werden. Dann kannst du einfach mit Form1.Variable auf die Variable zugreifen.

_________________
Der Autor dieses Textes haftet nicht für Schäden an Soft- oder Hardware
oder Vermögensschäden, die durch das Benutzen des Textes entstehen.
littlemike1005 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 187



BeitragVerfasst: So 19.10.03 11:22 
Titel: @Ja-Pa
Danke!!!!

Das ist ja so einfach da hätte man von selber drauf kommen können.

Danke Dir.

Michael
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: So 19.10.03 11:30 
oje oje, sowas ist aber von Hinten durch die Brust ins Linke Auge programmieren. Klassenübergreifende Programmierung ist aber nicht der feine Stil.

Besser wäre, einen eigenen Konstructor der 2. Form abzuleiten, dort die Variable zu übergeben und sie im eigenen Feld sichern.

Demo:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
type
  TForm1 = Class(TForm)
  private
    myString:String;
  end;
  TForm2 = Class(TForm)
  private
    myString: String;
  constructor MyCreate(AOwner:TComponent; AmyString:String);
  end;

constructor TForm2.MyCreate;
begin
  inherited Create(AOwner);
  myString:= amyString;
end;

in der Form1 rufst du auf:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
  My2Form: TForm2;
begin
  My2Form:= TForm2.MyCreate(Self,'TestString');
  My2Form.ShowModal;
  My2Form.Free;
end;

Form2 darf dabei nicht zur Liste der automatisch erstellen Forms gehören!

grez
msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?