Autor Beitrag
FSS
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Do 17.08.06 19:35 
Hallo,

ich habe da gerade ein Problem, das ich mir einfach nicht erklären kann.

Ich habe eine Variable vom Typ String : L1.
Nun möchte ich deren Inhalt als Eintrag in einer TComboBox anlegen:

ausblenden Delphi-Quelltext
1:
ComboBox1.Items.Add(L1);					


Der Eintrag wird auch angelegt, allerdings doppelt! Weiß jemand woran das liegt?
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 17.08.06 19:38 
Dann muss der Fehler im Code drumherum liegen. Zeig mal her!

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
FSS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Do 17.08.06 19:47 
Es gibt noch nicht nicht besonders viel code, ich lese den Inhalt von L1 aus einem Inifile aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
  Ini: TIniFile;
begin
  Ini := TInifile.Create(ExtractFilePath(Application.ExeName) + 'Data\daten.ini');
  L1 := Ini.ReadString('l1','title','');
  Ini.Free;
end;


Und dann kommt :

ausblenden Delphi-Quelltext
1:
ComboBox1.Items.Add(L1);					


Und ich kann wirklich nicht verstehen was da schief läuft :?: .
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: Do 17.08.06 19:55 
Also demnach ist da immer noch kein Fehler zu entdecken..
Wenn du vlt. dem kompletten Source posten würdest, dann waäre der Fehler sicherlich schnell lokalisiert.
(Meine Kristallkugel is mir nämlich ärgerlicherweise vorhin erst zu Bruch gegangen^^)
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 17.08.06 20:00 
user profile iconDanniolo hat folgendes geschrieben:
(Meine Kristallkugel is mir nämlich ärgerlicherweise vorhin erst zu Bruch gegangen^^)

Dann feg sie auf und versuch sie wieder zu kleben. :roll:
:mrgreen:
Ja, am besten mal bitte den gesamten Source.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
FSS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Do 17.08.06 20:05 
OK:

ausblenden volle Höhe 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:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
unit Unit3_waren;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, Buttons, Inifiles;

type
  Twaren = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    BitBtn1: TBitBtn;
    Label3: TLabel;
    edit_ware: TEdit;
    button_save: TBitBtn;
    auswahl: TComboBox;
    procedure auswahlKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer;
      var Resize: Boolean);
    procedure FormResize(Sender: TObject);
  private
    l1 : String;
    l2 : String;
    l3 : String;
    l4 : String;
    l5 : String;
    l6 : String;
    l7 : String;
    l8 : String;
    l9 : String;
    l10 : String;
    l11 : String;
    l12 : String;
    l13 : String;
    l14 : String;
    l15 : String;
    l16 : String;
    l17 : String;
    l18 : String;
    l19 : String;
    l20 : String;
    l21 : String;
    l22 : String;
    l23 : String;
    l24 : String;
    l25 : String;
    w1 : String;
    w2 : String;
    w3 : String;
    w4 : String;
    w5 : String;
    w6 : String;
    w7 : String;
    w8 : String;
    w9 : String;
    w10 : String;
    w11 : String;
    w12 : String;
    w13 : String;
    w14 : String;
    w15 : String;
    w16 : String;
    w17 : String;
    w18 : String;
    w19 : String;
    w20 : String;
    w21 : String;
    w22 : String;
    w23 : String;
    w24 : String;
    w25 : String;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  waren: Twaren;

implementation

uses Main;

{$R *.dfm}

procedure Twaren.FormResize(Sender: TObject);
begin
  MainForm.StatusBar1.Panels[1].Text := 'Aktuell: Waren ändern';
end;

procedure Twaren.FormCanResize(Sender: TObject; var NewWidth,
  NewHeight: Integer; var Resize: Boolean);
var
Ini : TIniFile;
begin
  Ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'Data\data\daten.lav');
  l1 := Ini.ReadString('l1','na','');
  l2 := Ini.ReadString('l2','na','');
  l3 := Ini.ReadString('l3','na','');
  l4 := Ini.ReadString('l4','na','');
  l5 := Ini.ReadString('l5','na','');
  l6 := Ini.ReadString('l6','na','');
  l7 := Ini.ReadString('l7','na','');
  l8 := Ini.ReadString('l8','na','');
  l9 := Ini.ReadString('l9','na','');
  l10 := Ini.ReadString('l10','na','');
  l11 := Ini.ReadString('l11','na','');
  l12 := Ini.ReadString('l12','na','');
  l13 := Ini.ReadString('l13','na','');
  l14 := Ini.ReadString('l14','na','');
  l15 := Ini.ReadString('l15','na','');
  l16 := Ini.ReadString('l16','na','');
  l17 := Ini.ReadString('l17','na','');
  l18 := Ini.ReadString('l18','na','');
  l19 := Ini.ReadString('l19','na','');
  l20 := Ini.ReadString('l20','na','');
  l21 := Ini.ReadString('l21','na','');
  l22 := Ini.ReadString('l22','na','');
  l23 := Ini.ReadString('l23','na','');
  l24 := Ini.ReadString('l24','na','');
  l25 := Ini.ReadString('l25','na','');
  w1 := Ini.ReadString('l1','wa','');
  w2 := Ini.ReadString('l2','wa','');
  w3 := Ini.ReadString('l3','wa','');
  w4 := Ini.ReadString('l4','wa','');
  w5 := Ini.ReadString('l5','wa','');
  w6 := Ini.ReadString('l6','wa','');
  w7 := Ini.ReadString('l7','wa','');
  w8 := Ini.ReadString('l8','wa','');
  w9 := Ini.ReadString('l9','wa','');
  w10 := Ini.ReadString('l10','wa','');
  w11 := Ini.ReadString('l11','wa','');
  w12 := Ini.ReadString('l12','wa','');
  w13 := Ini.ReadString('l13','wa','');
  w14 := Ini.ReadString('l14','wa','');
  w15 := Ini.ReadString('l15','wa','');
  w16 := Ini.ReadString('l16','wa','');
  w17 := Ini.ReadString('l17','wa','');
  w18 := Ini.ReadString('l18','wa','');
  w19 := Ini.ReadString('l19','wa','');
  w20 := Ini.ReadString('l20','wa','');
  w21 := Ini.ReadString('l21','wa','');
  w22 := Ini.ReadString('l22','wa','');
  w23 := Ini.ReadString('l23','wa','');
  w24 := Ini.ReadString('l24','wa','');
  w25 := Ini.ReadString('l25','wa','');

  auswahl.Items.Add(l1);
end;

procedure Twaren.auswahlKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  case key of
  vk_Return : BitBtn1.Click;
  end;
end;

end.
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: Do 17.08.06 20:10 
:shock: mach da auf jeden Fall erstma ne Schleife draus!

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:
[...]

  private
    l: Array [1..25] Of String;
    w: Array [1..25] Of String; 
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

[...]

procedure Twaren.FormCanResize(Sender: TObject; var NewWidth,
  NewHeight: Integer; var Resize: Boolean);
var
  Ini : TIniFile;
  i: Integer;
begin
  Ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'Data\data\daten.lav');
  For i := 1 To 25 Do
  Begin
    l[i] := Ini.ReadString('l'+IntToStr(i),'na','');
    w[i] := Ini.ReadString('l1'+IntToStr(i),'wa','');
  End;
  auswahl.Items.Add(l[1]);
end;

[...]


Dass das 2 mal hinzugefügt wird liegt wahrscheinlich daran, dass es in FormCanResize ist.
Probiers z.B. ma in OnFormCreate aus...
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Do 17.08.06 20:13 
Da ist kein Fehler, außer, dass du das INIFile-Objekt nicht freigibst. Ist das wirklich der ganze Code?
Aber es ist schon komisch, dass müsste dir doch auffallen, wenn du zweimal addest. aber an delphi kann es nicht liegen.

Vielleicht ist in dem string das zeichen #13, also die Return-Taste. Ich weiß nicht, ob TStrings dann eine neue Zeile draus macht...
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: Do 17.08.06 20:15 
Wie ich schon gesagt hab: wahrscheinlich liegts daran, dass es in FormCanResize ist..
Probiers halt ma woanders "drin" aus, also wie gesagt am besten OnFormCreate, denn dass wird normalerweise nur einmal aausgeführt^^
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Do 17.08.06 20:22 
Achja, Danniolo, das muss es sein. Vorraussetzung ist allerdings dafür, dass die Größe des Forms geändert wird. Wenn die Fenstergröße geändert wird, wird das Ereignis 2x ausgelöst. Habs grad ausprobiert.

in der hilfe steht das aber nicht direkt:
Zitat:

Das Ereignis OnCanResize wird ausgelöst, wenn die Größe des Steuerelements geändert werden soll.

Delphi-Syntax:

property OnCanResize: TCanResizeEvent;

C++ Syntax:

__property TCanResizeEvent OnCanResize = {read=FOnCanResize, write=FOnCanResize};

Beschreibung

Mit einer Ereignisbehandlungsroutine für OnCanResize können Sie festlegen, wie die Größe des Steuerelements angepasst wird. Ändern Sie hier gegebenenfalls Breite und Höhe der Komponente. In der Ereignisbehandlungsroutine kann auch angegeben werden, dass die gesamte Größenänderung abgebrochen werden soll.

Ist keine Behandlungsroutine für OnCanResize definiert, oder gibt die Ereignisbehandlungsroutine an, dass der Änderungsversuch fortgesetzt werden kann, wird direkt nach OnCanResize das Ereignis OnConstrainedResize ausgelöst.
FSS Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 83

Win 7 Professional 64Bit
Delphi 7 PE, Delphi 2005 PE, Turbo Delphi Explorer 2006
BeitragVerfasst: Do 17.08.06 20:25 
Ok, das mit dem Ini.Free das muss ich wohl irgendwie total übersehen haben.

Es liegt tatsächlich am FormCanResize.

Danke an alle!