Autor Beitrag
the-kecks
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157
Erhaltene Danke: 1

Windows Vista Home Premium 64Bit
Delphi 7 Ent.
BeitragVerfasst: Mo 16.03.09 22:54 
hi,
ich habe mal wieder ein problem...
mein code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TForm3.Button1Click(Sender: TObject);
var file1 : TStringlist;
begin
if not (pos(edit1.text, edit2.text) >0then
begin
 showmessage('Ungültige Zeile!');
 exit;
end
else
begin
 j:=StrToInt(edit1.text);
 file1:=TStringlist.Create;
 file1.LoadFromFile(Unit2.Dateipfad);
 file1[j]:=StringReplace(file1[j], Unit1.antwort, Unit1.new, [rfReplaceAll]); //hier liegt der fehler
 file1.SaveToFile(Unit2.Dateipfad);
 file1.free;
 Close;
 exit;
end;
end;


Stringreplace funzt nicht...die datei wird zwar geladen bleibt aber so wie sie ist -.- Ich hab keine Ahnung woran das liegen könnte. der gleiche code funzt an einer anderen stelle super!

mfg
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 16.03.09 23:11 
Was soll die if-Abfrage bewirken? Das sieht seltsam aus. Sie prüft jedenfalls nicht, ob eine gültige Zahl im Editzfeld steht, was eigentlich nötig wäre.

Wozu die globalen Variablen? Welche Werte haben die?
Fehlt in Dateipfad vielleicht die Pfadangabe?
the-kecks Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157
Erhaltene Danke: 1

Windows Vista Home Premium 64Bit
Delphi 7 Ent.
BeitragVerfasst: Mo 16.03.09 23:17 
oben wird abgefragt ob aus einer auswahl (edit2) auch ein wert genommen wurde.
dateipfad= pfad zur datei
antwort= altes qort in der datei nach erfolgreich gesucht wurde
new= dieses wort ersetzt antwort im string

mfg
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 16.03.09 23:21 
user profile iconthe-kecks hat folgendes geschrieben Zum zitierten Posting springen:
oben wird abgefragt ob aus einer auswahl (edit2) auch ein wert genommen wurde.
Wenn es eine Auswahl gibt, warum nimmst du dann keine ComboBox mit Style auf csDropDownList? :shock:

Setz doch einfach mal vor das StringReplace das:
ausblenden Delphi-Quelltext
1:
2:
ShowMessage('"' + file1[j] + '"'#13#10'"'
  + Unit1.antwort + '"'#13#10'"' + Unit1.new + '"');
oder nimm am besten ein Memo und poste was dann drin steht:
ausblenden Delphi-Quelltext
1:
2:
MemoX.Text := '"' + file1[j] + '"'#13#10'"' 
  + Unit1.antwort + '"'#13#10'"' + Unit1.new + '"';
Dann bist du sicher, dass j die richtige Zeile ist.
the-kecks Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157
Erhaltene Danke: 1

Windows Vista Home Premium 64Bit
Delphi 7 Ent.
BeitragVerfasst: Mo 16.03.09 23:26 
ok danke ich hatte vergessen, dass delphi in dateien nicht mit der zeile 1 sondern 0 anfängt.

mfg
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19341
Erhaltene Danke: 1752

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 17.03.09 00:02 
Dabei handelt es sich um ein Array und die fangen normalerweise immer bei 0 an, es sei denn man legt es extra anders fest bei einem statischen Array.

Die einzige Ausnahme sind ansonsten die Buchstaben in einem String. Deren Indizes fangen aus "historischen" Gründen bei 1 an, weil bei ShortStrings in Index 0 die Länge gespeichert wurde.