Autor Beitrag
flowstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 123

WinME
D6 Enterprise
BeitragVerfasst: Sa 15.05.04 13:46 
Warum funktioniert dieser Code nicht?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
var
  F : File;
begin
  AssignFile(F,'C:\WINDOWS\Desktop\test.html');
  rewrite(f);
  writeln('hallo');
  closefile(f);
end;


Der Fehler kommt immer bei writeln
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 15.05.04 13:53 
Versuch´s mal mit
ausblenden Delphi-Quelltext
1:
  F : TextFile;					
flowstar Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 123

WinME
D6 Enterprise
BeitragVerfasst: Sa 15.05.04 13:54 
nein das funktioniert auch nicht der Fehler tritt immernoch ein
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 15.05.04 13:59 
Hallo!

Du verrätsst uuns zwar nicht, wie dieser Fehler heißt, aber Du musst ihm bei WriteLn noch sagen, dass er auch in die Datei schreiben soll:

ausblenden Delphi-Quelltext
1:
WriteLn(f, 'hallo');					


Du solltest aber wirklich "F:Textfile" verwenden, wenn Du nur Text speichern willst.

MfG
Peter

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

WinME
D6 Enterprise
BeitragVerfasst: Sa 15.05.04 14:02 
ok danke jetzt funktioniert es
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 15.05.04 15:25 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button1Click(Sender: TObject); 
var 
  F : TextFile; 
begin 
  AssignFile(F,'C:\WINDOWS\Desktop\test.html'); 
{$I-}
  rewrite(f); 
{$I+}
  if IOResult = 0 then
  begin
    writeln('hallo', f); 
    closefile(f); 
  end
  else
    ShowMessage(SysErrorMessage(GetLastError));
end;

So ist es korrekt, inklusive Fehlerbehandlung.
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 16.05.04 08:43 
Na ja, noch besser wär´s so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
{$I-}
AssignFile(...);
{ ... }
CloseFile(...);
{$I+}

Falls bei "WriteLn" was schief geht, fängt man das damit auch ab und kann dann am Ende ja das Ergebnis von "IoResult" prüfen bzw. anzeigen.