Autor Beitrag
neuling321
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18

Win10prof
Delphi 10 Seattle Prof.
BeitragVerfasst: Sa 21.05.16 17:13 
Hallo

Ich möchte mittel dieser Procedure TComboBoxen befüllen.
Leider bekomme ich eine Fehlermeldung und weiss nicht genau warum.
Die Werte werden aus einer ini Datei geholt, das klappt soweit auch gut.
Es scheitert an den Namen der Comboboxen, die ich beim Aufruf der Procedure
mit übergebe.
Hier der Code:

Aufruf:
ausblenden Delphi-Quelltext
1:
  fillcombo('combowertb''material''matwert');					


Procdedure:
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:
procedure TForm1.fillcombo(ComboName, iniSection, iniKey : String);
var
  I : integer;
  strIniKey : String;
  strIniKeyALL : TStringList;

begin
  strIniKeyALL:= tstringlist.Create;

  ALLinOneIni := tinifile.Create('.\test.ini');
  try;
    for I := 1 to 50 do begin
      strIniKey := ALLinOneIni.ReadString(iniSection, iniKey + inttostr(I),'');
      if strIniKey <> '' then
      begin
        strIniKeyALL.Add(strIniKey);
      end;
    end;
  finally
    ALLinOneIni.Free;
  end;

    TComboBox(ComboName).Items.Assign(strIniKeyALL);  <--- Hier muss der Fehler liegen

end;


ini-Datei:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
[material]
matname1=Eiche
matwert1=1
matname2=Buche
matwert2=2
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 21.05.16 17:43 
Hallo,

Du kannst den String Comboname nicht einfach in eine TComboBox casten. Was Du brauchst, ist Suche in der Entwickler-Ecke FINDCOMPONENT.

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
neuling321 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18

Win10prof
Delphi 10 Seattle Prof.
BeitragVerfasst: Sa 21.05.16 19:50 
Danke schön, jetzt klappt es :-)
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: Mo 23.05.16 08:55 
Ich erlaube mir mal, Deine Procedure etwas umzuschreiben. Denn sie hat ein paar Probleme.
Vor alllem gibst Du strIniKeyAll nicht mehr frei, Du hast also ein Speicherleck.
Wenn Du den Aufruf etwas veränderst und nicht den Namen der Combobox übergibst, sondern eine Referenz auf die Combobox selber, würdest Du Dir auch FindComponent sparen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.fillcombo(AComboBox : TComboBox; iniSection, iniKey : String);
var
  I : integer;
  strIniKey : String;

begin

  ALLinOneIni := tinifile.Create('.\test.ini');
  try
    for I := 1 to 50 do begin
      strIniKey := ALLinOneIni.ReadString(iniSection, iniKey + inttostr(I),'');
      if strIniKey <> '' then
      begin
        AComboBox.Items.Add(strIniKey);
      end;
    end;
  finally
    ALLinOneIni.Free;
  end;

end;


Der Aufruf sähe dann so aus:
ausblenden Delphi-Quelltext
1:
fillcombo(combowertb, 'material''matwert');					


So ist es etwas hübscher.

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)
neuling321 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18

Win10prof
Delphi 10 Seattle Prof.
BeitragVerfasst: So 29.05.16 13:31 
Hallo Jens

Ich bekomme nun bei AComboBox undeklarierter Bezeichner.
Habe ich da irgendwas vergessen?
Nersgatt
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1581
Erhaltene Danke: 279


Delphi 10 Seattle Prof.
BeitragVerfasst: So 29.05.16 18:18 
Hast Du auch den Teil im Interfaceteil angepasst?

_________________
Gruß, Jens
Zuerst ignorieren sie dich, dann lachen sie über dich, dann bekämpfen sie dich und dann gewinnst du. (Mahatma Gandhi)