Autor Beitrag
ConditionZero
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: Mi 27.12.06 13:51 
Moin,
Situation: Ich möchte eine ComboBox machen die alle .txt dateien in einem Ordner anzeigt, mit dem Programm kann man neue Textdokumente anlegen und diese Selbstangelegten Dateien sollen eben angezeigt werden in einer ComobBox.

Code zum Anlegen neuer Dateien:
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:
procedure TForm2.Button1Click(Sender: TObject);
var
  sl : tstringlist;
  path : string[255];
  Text : textfile;
//  str : string;
begin
  path := extractfilepath(application.exename);
  path := IncludeTrailingBackslash(path);
  path := path + 'Fragen\';
  if not (richedit1.Lines.Text = '') and not
         (richedit2.lines.text = '') then
  begin
    if not (edit1.text = '') then
    begin
      if ForceDirectories(path) then begin end;

      if not fileexists(path + edit1.text + '.txt') then
        filecreate(path + edit1.text + '.txt');

      assignfile(text, path + edit1.text + '.txt');
      append(text);
      writeln(text, richedit1.lines.commatext);
      writeln(text, richedit2.lines.commatext);
      closefile(text);
    end;
  end;
end;



Meine Frage, wie kann ich das machen, das bei ComboBox1.items.add() hinzugefügt wird wie eine neu angelegte textdatei heißt?


LG
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Mi 27.12.06 14:40 
Vielleicht hab ich deine Frage nicht richtig verstanden.

user profile iconConditionZero hat folgendes geschrieben:
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:
29:
procedure TForm2.Button1Click(Sender: TObject);
var
  sl : tstringlist;
  path : string[255];
  Text : textfile;
//  str : string;
begin
  path := extractfilepath(application.exename);
  path := IncludeTrailingBackslash(path);
  path := path + 'Fragen\';
  if not (richedit1.Lines.Text = '') and not
         (richedit2.lines.text = '') then
  begin
    if not (edit1.text = '') then
    begin
      if ForceDirectories(path) then begin end;

      if not fileexists(path + edit1.text + '.txt') then
        filecreate(path + edit1.text + '.txt');

      ComboBox1.items.add(path + edit1.text + '.txt'); //einfach den Dateinamen mit deiner methode hinzufügen?! war das die richtige antwort auf deine frage?
      assignfile(text, path + edit1.text + '.txt');
      append(text);
      writeln(text, richedit1.lines.commatext);
      writeln(text, richedit2.lines.commatext);
      closefile(text);
    end;
  end;
end;
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: Mi 27.12.06 16:48 
Ja des wars... danke

Speichert das die items von der ComboBox also wenn ich die Form schließ und nochmal neu aufmach, sind die dann noch drinnen?
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Mi 27.12.06 16:52 
nein, bevor du das Form schließt (am besten OnDestroy) musst du Combobox1.Items.SavetoFile('Dateiname von deiner Listendatei.txt') aufrufen,
und dann OnCreate Combobox1.Items.LoadFromFile('Dateiname von deiner Listendatei.txt')
ConditionZero Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: Mi 27.12.06 16:53 
ah ok, geht das auch in ini dateien also wenn ich einfach .ini statt .txt dranhänge?