Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   FreePascal (https://www.delphipraxis.net/74-freepascal/)
-   -   ComboBox Problem (https://www.delphipraxis.net/177339-combobox-problem.html)

ironman139 1. Nov 2013 09:31

ComboBox Problem
 
Hallo,

Ich hab ein kleines Problem mit Lazarus.

Ich hab in meinem Form1 2 ComboBoxen in welchen Daten gespeichert sind.
Dieses angezeigte Item will ich an ein 2. Form weitergeben.
In dem Form 2 rufe ich die Daten mit " label9.caption:= Form1.Combobox1.text; " ab.
Das Funktioniert soweit auch, nur übernimmts mir da nur die Daten von Form1, die bei der OnCreate Methode eingestellt sind.
Also wenn ich die Combox ändere und dann in Form2 übernehmen will, zeigts mir trotzdem nur das Item an , welches bei OnCreate eingetragen war.


mfg. iron

markus5766h 1. Nov 2013 11:13

AW: ComboBox Problem
 
Hallo, herzlich willkommen in der DP.

Du musst auf die Änderung der ComboBox reagieren,
hierfür gibt es das Ereignis OnChange der ComboBox.
Alternativ kannst Du auch den Wert über die Items
--> ComboBox1.Items[ItemIndex] abfragen.
Delphi-Quellcode:
if ComboBox1.ItemIndex > -1 then Form2.Label1.Caption := ComboBox1.Items[ComboBox1.ItemIndex];

Union 1. Nov 2013 11:29

AW: ComboBox Problem
 
Zitat:

Zitat von ironman139 (Beitrag 1234119)
Hallo,
In dem Form 2 rufe ich die Daten mit " label9.caption:= Form1.Combobox1.text; " ab.

Zu welchem Zeitpunkt findet denn dieser "Abruf" statt?

ironman139 1. Nov 2013 11:37

AW: ComboBox Problem
 
Der Abruf findet statt, wenn ich einen Button drück.
Dann erscheint das Form2

markus5766h 1. Nov 2013 11:47

AW: ComboBox Problem
 
. . . dann sollte's doch so gehen
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Form2.Visible then Form2.Show;
  if ComboBox1.ItemIndex > -1 then Form2.Label9.Caption := ComboBox1.Items[ComboBox1.ItemIndex];
end;
oder

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if not Form2.Visible then Form2.Show;
  Form2.Label9.Caption := ComboBox1.Text;
end;

ironman139 1. Nov 2013 12:45

AW: ComboBox Problem
 
Danke ihr habt mir sehr geholfen


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:16 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz