[Delphi] Pewien błąd plikowy

0

nie mogę rozwiązać pewnego problemu ???

chodzi o else;
błąd jest oznaczony pogrubioną kursywą

unit introder;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;

type
TForm1 = class(TForm)
Memo2: TMemo;
GroupBox1: TGroupBox;
Button2: TButton;
Button1: TButton;
Memo1: TMemo;
BitBtn1: TBitBtn;
Button3: TButton;
Button4: TButton;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
VAR
TF : TextFile;
r, m, d :word;
mi :string;
begin
DecodeDate(date, r, m, d);
if m=9 then
mi:='WRZESIEŃ ';
if m=10 then
mi:='PAŹDZIERNIK ';
if m=11 then
mi:='LISTOPAD ';
if m=12 then
mi:='GRUDŹIEŃ ';
if m=1 then
mi:='STYCZEŃ ';
if m=2 then
mi:='LUTY ';
if m=3 then
mi:='MARZEC ';
if m=4 then
mi:='KWIECIEŃ ';
if m=5 then
mi:='MAJ ';
if m=6 then
mi:='CZERWIEC ';
if m=7 then
mi:='LIPIEC ';
if m=8 then
mi:='SIERPIEŃ ';
if fileexists (ExtractFilePath( Application.ExeName ) + mi + Format('%d',[R]) + '.txt') then showmessage('Plik dziennika istnieje.')
else AssignFile(TF, ExtractFilePath( Application.ExeName ) + mi + Format(' %d',[R]) + '.txt' ); * przypisanie pliku do zmiennej }
Rewrite(TF); * utworzenie pliku
try
finally
CloseFile(TF);
end;
memo2.Lines.LoadFromFile(( ExtractFilePath( Application.ExeName ) + mi + format ('%d',[r]) + '.txt'));

end;

procedure TForm1.Button4Click(Sender: TObject);
{ Jak ZDEKODOWAĆ datę ? }
var
r, m, d :word;
mi :string;
begin
DecodeDate(date, r, m, d);
if m=9 then
mi:='WRZEŚNIA ';
if m=10 then
mi:='PAŹDZIERNIKA ';
if m=11 then
mi:='LISTOPADA ';
if m=12 then
mi:='GRUDNIA ';
if m=1 then
mi:='STYCZNIA ';
if m=2 then
mi:='LUTEGO ';
if m=3 then
mi:='MARCA ';
if m=4 then
mi:='KWIETNIA ';
if m=5 then
mi:='MAJA ';
if m=6 then
mi:='CZERWCA ';
if m=7 then
mi:='LIPCA ';
if m=8 then
mi:='SIERPNIA ';
memo1.lines.add( Format(' %d ' ,[D]) + mi + Format('%d ',[r]));
end;

end.

Proszę pomóżcie :(
--Delphi 2 , 6 i 5
Ciekawe pomysły i poszukiwanie rozwiązań.

0

Powinieneś jeszcze napisać na czym problem polega - tzn. co się dzieje po uruchomieniu tego, co tu przytoczyłeś.
Nie mam tu kompilatora i nie mogę tego sam sprawdzić, ale myślę, że chodzi o to, że program kasuje zawartość pliku, jeśli ten istnieje.
Jeśli tak, to begin i end po else powinny pomóc. Jeśli nie, to napisz dokładniej jaki masz problem.

0

Nie wiem dlaczego tak jest z tym AssignFile ale u mnie jak nie istnieje plik to wywala błąd :) i chyba tobie też :)

0

Hm Mi wyglaa na to ze jesli plik nieistnieje to jest wszystko OK, jesli istnieje to po ShowMessage jest wykonywane Rewrite i tu wywali blad ze zmianna TF nie jest przypisana przez AssignFile

Sprobuj tak:
if FileExists(ExtractFilePath(Application.ExeName)+mi+Format('%d',[R])+'.txt') then
begin
showmessage('Plik dziennika istnieje.');
end else begin
AssignFile(TF, ExtractFilePath(Application.ExeName)+mi+Format(' %d',[R]) +'.txt' );
Rewrite(TF);
CloseFile(TF);
end;--W poszukiwaniu rozwiązania problemu, najbardziej pomocna jest znajomość odpowiedzi.

1 użytkowników online, w tym zalogowanych: 0, gości: 1