Autor Beitrag
bayou
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88


D6 PE
BeitragVerfasst: Do 18.05.06 08:48 
hallo nochmal,

ich möchte über Form1, length der Checklistbox1 aus Form2 ermitteln.

über Form1
ausblenden Quelltext
1:
Form2.Width := Length(Form2.CheckListBox1.Items.Strings[j])*2;					

Hier greif ich aber auf length der Form1 zu. (Form1 habe ich auch eine Checklistbox1)

was ich machen möchte ist:
Die Breite der Form2 an die Länge des längsten Strings in Form2.Checklistbox1 anpassen.

ich hoffe Ihr wisst was ich meine.

schon mal vielen dank
bayou

Moderiert von user profile iconGausi: Titel "entcapst".
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Do 18.05.06 08:50 
*grübl*
machst du das nicht schon in deinem beispiel?
und wo tritt in deinem beispiel form1 auf?
*grübl*


UND WARUM MUSS MAN THREAD TITEL GROSS SCHREIBEN?

_________________
Delphi: XE - OS: Windows 7 Professional x64
bayou Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88


D6 PE
BeitragVerfasst: Do 18.05.06 09:18 
Die Prozedur kommt aus Form1.

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:
procedure TForm1.CheckListBox1Click(Sender: TObject);
var
  i, j: Integer;
begin
  i := CheckListBox1.ItemIndex;  // aus Form1.CkeckListBox1
  if (i > -1) then begin 
    CurrentFigure := TFigure(CheckListBox1.Items.Objects[i]);  // aus Form1.CkeckListBox1
    if (Form2.Visible = true) then 
      Form2.CheckListBox1.Items.Assign(CurrentFigure.Subfigure);  // Form2
      if (Form2.CheckListBox1.Count > 0) then begin
         Form2.Height := Form2.CheckListBox1.ItemHeight* (FormSubFigure.CheckListBox1.Count +1);
         // Hier ist lenght aber von Form1. Der Wert in Klammer gibt ja nur die Länge an.         
         Form2.Width := Length(Form2.CheckListBox1.Items.Strings[j])*1;  
      end
      else begin
        Form2.Height := Form2.CheckListBox1.ItemHeight*1;
        Form2.Width := 400;
      end;
  end
  else begin 
    CurrentFigure := NIL;
  end;
end;


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Do 18.05.06 09:28 
user profile iconbayou hat folgendes geschrieben:


ausblenden Quelltext
1:
2:
         // Hier ist lenght aber von Form1. Der Wert in Klammer gibt ja nur die Länge an.         
         Form2.Width := Length(FormSubFigure.CheckListBox1.Items.Strings[j])*1;


Length ist von Form1?

Length ist doch nur eine Funktion die dir die Länge eines Strings zurückgibt.

Hat doch mit Form1 gar nichts zu tun.

_________________
Delphi: XE - OS: Windows 7 Professional x64
bayou Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88


D6 PE
BeitragVerfasst: Do 18.05.06 10:04 
Also ich glaube du hast recht. War ein Gedankenfehler von mir.
Bin halt absoluter Delphi Anfänger mit sehr wenig Ahnung.

Auf jeden Fall bekomme ich einen Fehler "Listindex out of bounds".
Ich dachte das währe der Fehler.

Kann mir jemand helfen? Ich hab bisher noch nichts gefunden.

1000 Dank
bayou
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Do 18.05.06 10:27 
du greifst auf den String mit index j zu.
j hast du aber noch keinen Wert zugewisen (zumindest soweit ich das gerade sehe)

achte darauf, dass j einem gültigen index entspricht

_________________
Delphi: XE - OS: Windows 7 Professional x64
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 18.05.06 10:38 
Hallo,

die Variable j ist als lokale Variable in TForm1.CheckListBox1Click deklariert und wird nicht initialisiert, hat also einen zufälligen Wert.
Diesen Wert nutzt Du dann in :
ausblenden Delphi-Quelltext
1:
Form2.Width := Length(Form2.CheckListBox1.Items.Strings[j])*1;					

Wenn dieser zufällige Wert größer als Form2.CheckListBox1.Count-1 ist, hast Du die Bereichsüberschreitung.

Außerdem gibt Dir Length die Anzahl der Zeichen in Form2.CheckListBox1.Items.Strings[x] zurück. Die Breite des Strings in Pixel kannst Du mit Canvas.TextWidth feststellen, das benötigst Du um Form2.Width entsprechend einzustellen.

Width bestimmt die Breite in Pixel.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
bayou Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88


D6 PE
BeitragVerfasst: Do 18.05.06 10:40 
Hi und vielen Dank für deine Antwort.
hab jetzt
ausblenden Delphi-Quelltext
1:
  for j := 0 to CheckListBox1.Items.Count -1 do					

davor gesetzt. Es kommt aber immer noch der Fehler "Listindex out of bounds"

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Do 18.05.06 10:50 
WO genau hast du das davor gesetzt?
(zeig mal die folgende zeile dazu)

_________________
Delphi: XE - OS: Windows 7 Professional x64
bayou Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88


D6 PE
BeitragVerfasst: Do 18.05.06 10:54 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
      if (FormSubFigure.CheckListBox1.Count > 0) then begin
        FormSubFigure.Height := FormSubFigure.CheckListBox1.ItemHeight*(FormSubFigure.CheckListBox1.Count +1);
        for j := 0 to CheckListBox1.Items.Count -1 do
          FormSubFigure.Width := Canvas.TextWidth(FormSubFigure.CheckListBox1.Items.Strings[j])*2;
      end
      else begin
        FormSubFigure.Height := FormSubFigure.CheckListBox1.ItemHeight*1;
        FormSubFigure.Width := 400;
      end;


thx

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Do 18.05.06 10:58 
user profile iconbayou hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
      if (FormSubFigure.CheckListBox1.Count > 0) then begin
        FormSubFigure.Height := FormSubFigure.CheckListBox1.ItemHeight*(FormSubFigure.CheckListBox1.Count +1);
        for j := 0 to CheckListBox1.Items.Count -1 do
          FormSubFigure.Width := Canvas.TextWidth(FormSubFigure.CheckListBox1.Items.Strings[j])*2;
      end
      else begin
        FormSubFigure.Height := FormSubFigure.CheckListBox1.ItemHeight*1;
        FormSubFigure.Width := 400;
      end;


thx


Das ist nicht die gleiche CheckListBox! Änder das ab, dass du dich beides mal auf die CheckListBox in FormSubFigure beziehst

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt

_________________
Delphi: XE - OS: Windows 7 Professional x64
bayou Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88


D6 PE
BeitragVerfasst: Do 18.05.06 11:50 
Ähhhm ja :oops:

dann kann das ja nur den Fehler gehn.

nochmals vielen Dank
Horschdware
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 744
Erhaltene Danke: 54

Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
BeitragVerfasst: Do 18.05.06 12:00 
kein problem.

aber verwende doch in zukunft bitte delphi tags stat code tags

-> [ d e l p h i ] und [ / d e l p h i ]

_________________
Delphi: XE - OS: Windows 7 Professional x64
bayou Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88


D6 PE
BeitragVerfasst: Do 18.05.06 12:29 
OK Danke

ich mach mal das Thema zu