| Autor |
Beitrag |
Tigu
      
Beiträge: 93
XP
Delphi 7
|
Verfasst: Mi 22.02.06 18:31
Hallo!
Ich muss Daten aus einer ListBox in einer Editordatei speichern.
Habe bis jetzt den folgenden Quelltext:
Delphi-Quelltext 1:
| ListBox1.Items.SaveToFile('gespeicherte_Tiere.txt'); |
Ich habe dabei nur unsere Einleseaufforderung
Delphi-Quelltext 1:
| ListBox1.Items.LoadFromFile('gespeicherte_Tiere.txt'); |
umgeschrieben, weil ich keine Ahnung habe, wie man das macht.
Ich dachte, dass man eine Speicherung in einer Editordatei immer bestätigen muss. Laut meines Lehrers muss es eine Möglichkeit geben, dass der Projektbenutzer nicht mitbekommt, dass die Liste gespeichert wird.
Bitt helft mir.
Danke für alle Vorschläge
Tigu
|
|
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Mi 22.02.06 18:38
Du musst bei dem Code nichts bestätigen. Ich habe nicht verstanden, was du für ein Problem hast. 
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Tigu 
      
Beiträge: 93
XP
Delphi 7
|
Verfasst: Mi 22.02.06 18:40
Hallo Koller!
Das mit dem Eintragen in die Editordatei funktioniert so bei mir nicht.
Hast du eine Idee, wie man es anders oder besser machen könnte?
Danke für deine Hilfe
Tigu
|
|
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Mi 22.02.06 18:46
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Tigu 
      
Beiträge: 93
XP
Delphi 7
|
Verfasst: Mi 22.02.06 18:56
Hört sich zwar logisch an, funktioniert aber leider nicht.
Tigu
|
|
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Mi 22.02.06 18:59
Tigu hat folgendes geschrieben: | | funktioniert aber leider nicht. |
Das kann ich nicht leiden
Du musst schon sagen, was genau nicht geht. Fehlt die Datei? Fehlermeldung? Exception? Oder gib mal den betreffenden Code (auch das darum;) )
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Tigu 
      
Beiträge: 93
XP
Delphi 7
|
Verfasst: Mi 22.02.06 19:00
Hört sich zwar logisch an, funktioniert aber leider nicht.
Tigu
|
|
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Mi 22.02.06 19:02
AHA - du hast Recht 
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Tigu 
      
Beiträge: 93
XP
Delphi 7
|
Verfasst: Mi 22.02.06 19:04
Er zeigt mir keinen Fehler an, aber ich habe den Listboxinhalt nicht in meiner Editdatei.
Tigu
Der komplette 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:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls;
type TForm1 = class(TForm) Feld: TStringGrid; Label1: TLabel; BnEnde: TButton; Buchstaben_liste: TListBox; BnEintragen: TButton; BnSuchen: TButton; Edit1: TEdit; Button1: TButton; Label2: TLabel; ListBox1: TListBox; Label3: TLabel; Button2: TButton; procedure FormCreate(Sender: TObject); procedure BnEndeClick(Sender: TObject); procedure BnEintragenClick(Sender: TObject); procedure eintragen; procedure FeldDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure BnSuchenClick(Sender: TObject); procedure Button1Click(Sender: TObject); procedure BnladenClick(Sender: TObject); procedure BnSpeichernClick(Sender: TObject); private public procedure suchen; end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject); var x,y:integer; begin if fileexists('buchstaben_liste.txt') then begin buchstaben_liste.Items.LoadFromFile('buchstaben_liste.txt'); end;
for x:=feld.fixedCols to feld.ColCount -1 do feld.Cells[x,0]:=chr(65+x-1); for y:=feld.fixedRows to feld.RowCount-1 do feld.Cells[0,y]:=IntToStr(y); end;
procedure TForm1.eintragen; var x,y:integer; begin buchstaben_liste.Itemindex:=0; for y:=1 to feld.ColCount -1 do begin for x:=feld.FixedRows to feld.RowCount -1 do begin feld.Cells[x,y]:=buchstaben_liste.Items[buchstaben_liste.Itemindex]; buchstaben_liste.ItemIndex:=buchstaben_liste.Itemindex+1; end; end; end;
procedure TForm1.BnEintragenClick(Sender: TObject); begin eintragen; end;
procedure TForm1.Button1Click(Sender: TObject); begin eintragen; end;
procedure TForm1.FeldDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var s:string; begin s:=feld.Cells[acol,arow]; if length(s)>0 then if s[1] in ['a'..'z'] then begin feld.Canvas.Rectangle(Rect); feld.Canvas.Font.Color:=clred; feld.Canvas.TextOut(Rect.Left+2,rect.Top+2,s); feld.Canvas.Font.Color:=clblack; end; end;
procedure TForm1.Suchen; var x,y,i:integer; Suchwort:string; gefunden:boolean; begin Suchwort:=Edit1.Text; for y:=1 to feld.RowCount - 1 do begin for x:=feld.FixedCols to feld.colcount - 1 do begin if feld.Cells[x,y]=Suchwort[1] then begin gefunden:=true; for i:=2 to length(suchwort) do if feld.Cells[x+i-1,y]<>suchwort[i] then gefunden:=false; if gefunden then for i:=1 to length(Suchwort) do feld.Cells[x+i-1,y]:=LowerCase(feld.Cells[x+i-1,y]); begin gefunden:=true; for i:=2 to length(suchwort) do if feld.Cells[x,y+i-1]<>suchwort[i] then gefunden:=false; if gefunden then for i:=1 to length(Suchwort) do feld.Cells[x,y+i-1]:=LowerCase(feld.Cells[x,y+i-1]); end; end; end; end; ListBox1.Items.Add(Suchwort); end;
procedure TForm1.BnSuchenClick(Sender: TObject); begin suchen; end;
procedure TForm1.BnladenClick(Sender: TObject); begin if fileexists('gespeicherte_Tiere.txt') then ListBox1.Items.LoadFromFile('gespeicherte_Tiere.txt'); end;
procedure TForm1.BnEndeClick(Sender: TObject); begin close; end;
procedure TForm1.BnSpeichernClick(Sender: TObject); begin Listbox1.Items.SaveToFile(ExtractFilePath(ParamStr(0))+'gespeicherte_Tiere.txt'); end;
end. |
|
|
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Mi 22.02.06 19:06
Wird die Datei denn angelegt und es ist kein Inhalt drin? Und erklär mir mal, was du genau mit Editdatei meinst.
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Tigu 
      
Beiträge: 93
XP
Delphi 7
|
Verfasst: Mi 22.02.06 19:11
Wir sollen den Inhalt in eine vorhandene Editdatei, welche im gleichen Ordner gespeichert ist, speichern.
Darum meinte ich vorhin, dass man das Speichern eigentlich bestätigen muss.
Tigu
|
|
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Mi 22.02.06 19:13
Ich weiß, immer noch nicht, inwiefern man da was bestätigen musst. Willst du den Dateinamen und den Ort zur Laufzeit festlegen lassen?
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Tigu 
      
Beiträge: 93
XP
Delphi 7
|
Verfasst: Mi 22.02.06 19:14
Wenn es mit einem Worddokument besser funktioniert, dann geht auch das.
|
|
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Mi 22.02.06 19:14
Die Frage ist auch, warum das nicht gespeichert wird. Kannst du mir das Programm (die exe) mal senden/hochladen?
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Tigu 
      
Beiträge: 93
XP
Delphi 7
|
Verfasst: Mi 22.02.06 19:19
In meinem Ordner soll es ein Dokument oder Ähnliches geben.
Dieses ist fest.
Dort hinein soll am Ende des Spielens der Inhalt der ListBox eingetragen werden.
Einloggen, um Attachments anzusehen!
|
|
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Mi 22.02.06 19:24
Wo ist denn der Speichern Button?
Edit: Ich sehe grade dass nachm Klick auf Ende die Datei da ist mit dem Inhalt. Was meinst du dazu?
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Tigu 
      
Beiträge: 93
XP
Delphi 7
|
Verfasst: Mi 22.02.06 19:28
Bei mir ist der Speicherbutton direkt unter dem Endebutton.
Bei Ende stet nur close; drin und bei Speichern das, was du vorhin geschrieben hast.
|
|
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Mi 22.02.06 19:31
Wie gesagt - wenn ich auf Ende klicke, dann wirds gespeichert. Ich schau mir den Code mal an-
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Mi 22.02.06 19:33
Du scheinst irgendwie den Speichern und den Ende-Button vertauscht zu haben. Ich kann mir das auch nicht erklären. Lad ma dein gesamtes Projekt hoch.
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
Tigu 
      
Beiträge: 93
XP
Delphi 7
|
Verfasst: Mi 22.02.06 19:39
Hier der Rest (hoffe es ist alles)
Einloggen, um Attachments anzusehen!
|
|