Autor Beitrag
Arbengie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66



BeitragVerfasst: Sa 09.01.10 22:08 
Hi, hab mal wieder ne Frage:

Ich in einem Programm nun 2 Forms, und ich möchte wissen wie ich Werte aus einer Unit in die andere Unit bekomme.
Genauer gesagt habe ich in in Unit2 ein Edit Feld, wo man eine Zahl einträgt, damit sich z.B. eine Buttongröße in Unit1 verändert.
Wie bekomme ich das nun hin?

MFG
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 09.01.10 22:18 
Nimm die entsprechende Unit bei der anderen in die Uses-Anweisung auf. Ggf. unterhalb von Implementation, weil du sonst Zirkelbezüge reinbekommen könntest.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 10.01.10 02:07 
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: So 10.01.10 16:33 
Also ich denke, dass es am einfachsten so geht:
Du musst doch eigentlich nur eine Procedure in Form1 auf public setzen - also unter public definieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
private
{...}
public
   procedure ButtonGroesseAendern(neuerWert:integer);

und dann müsste dieses für das ändern der Breite in dieser Haupform reichen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure Form1.ButtonGroesseAendern(neuerWert:integer);
begin
ButtonDessenGroesseZuAendernIst.Width:=neuerWert;
end;

Und in der Form2 brauch dann nur der folgende Aufruf zu sein:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure Form2.ButtonAendernClick(Sender:Tobject);
begin
try
Form1.ButtonGroesseAendern(StrToInt(TextBoxWert.Text));
except
   Messagebox('Der Wert konnte nicht in einen Int-Wert umgewandelt werden!'+#13#10+' - Tippfehler?');
end;
end;
Arbengie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66



BeitragVerfasst: So 10.01.10 20:09 
Jetz bin ich in Unit2 und der soll die Größe der Form1 ändern:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
uses Unit1;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  If RadioButton2.Checked=True then
  begin
  Form1.Width:='1024' and Form1.Height:='768'
 [b] end[/b]


aber es kommt immer der Fehler:

[Error] Unit2.pas(39): Incompatible types: 'Integer' and 'String'
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: So 10.01.10 20:13 
hochkomma vor und nach den Zahlen weglassen und du hast die lösung. ;)

Hochkommas markieren immer Strings!

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Arbengie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66



BeitragVerfasst: So 10.01.10 20:49 
jetzt kommt die fehlermeldung:

[Error] Unit2.pas(39): Operator not applicable to this operand type

:roll:
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: So 10.01.10 20:51 
Lass das and weg, und mach zwei Befehle draus.

_________________
PROGRAMMER: A device for converting coffee into software.
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: So 10.01.10 21:51 
Ja, das sind für den Compiler ganz einfach zwei voneinander recht unabhängige, nacheinander abzuarbeitende Befehle.
Also sollte es dann genau so klappen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
 uses Unit1;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  If RadioButton2.Checked=True then
  begin
  Form1.Width:=1024
  Form1.Height:=768;
  end;
end;


---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

Wobei ich da immer wieder überlege, ob man da denn überhaupt fragen sollte:
"ist es wahr, dass etwas wahr ist".
Eigentlich reicht es doch auch, wenn man dort nur
ausblenden Delphi-Quelltext
1:
if RadioButton2.Checked then					

schreibt.
Und wenn man nur fragen möchte, ob etwas nicht wahr ist (also wenn man nur den negativen Fall haben möchte), dann so:
ausblenden Delphi-Quelltext
1:
if not RadioButton2.Checked then					
FinnO
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1331
Erhaltene Danke: 123

Mac OSX, Arch
TypeScript (Webstorm), Kotlin, Clojure (IDEA), Golang (VSCode)
BeitragVerfasst: So 10.01.10 22:37 
Mit dem Leidigen Thema mit dem Vergleich auf True hat mir hier ja echt ständig zu tun. Das ganze ist nicht nur überflüssig sonden in einigen Fällen schlicht und ergreifend falsch.
Arbengie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66



BeitragVerfasst: Mo 11.01.10 20:51 
Jetzt tritt das eigentliche Problem wieder auf:

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:
uses Unit1;

{$R *.dfm}

procedure TForm2.ButtonSpeichernClick(Sender: TObject);
begin
  If RadioButton2.Checked=True then
  begin
  Form1.Width:=1024;
  Form1.Height:=768;
  end;

  If RadioButton1.Checked=True then
  begin
  Form1.Width:=800;
  Form1.Height:=600;
  WebBrowser1.Width:=787;
  WebBrowser1.Height:=489;
  end;

  If RadioButton3.Checked=True then
  begin
  Form1.Width:=640;
  Form1.Height:=480
  end
end;

end.


WebBrowser1 tritt in Unit1 auf, aber er sagt:

[Error] Unit2.pas(46): Undeclared identifier: 'WebBrowser1'
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mo 11.01.10 20:53 
ja, klar. wenn du nicht dazuschreibst auf welchem Form die Komponente zu finden ist, nimmt er die, in der die Methode definiert wurde.

Lösung:

ausblenden Delphi-Quelltext
1:
Form1.WebBrowser1.MachDeinenBefehl();					


lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Arbengie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 66



BeitragVerfasst: Mo 11.01.10 21:15 
Ah ok, habs gefunden. Danke.

Aber jetz compiliert der das zwar, aber es komm diese Nachricht:

Screenshot

Was bedeutet das nun wieder?

Moderiert von user profile iconNarses: Bild als Anhang hochgeladen.
Einloggen, um Attachments anzusehen!
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mo 11.01.10 21:44 
das ist ein CPU fenster zum debuggen. hast du einen Breakpoint in deinem Quelltext? (kleine Rote punkte am rand einer Zeile im Editor) oder vielleicht sogar nen Fehler in deinem Programm?

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.