Einzelnen Beitrag anzeigen

gammatester

Registriert seit: 6. Dez 2005
999 Beiträge
 
#5

AW: Prüfen ob eine Dateivariable mit Assign zugewiesen ist

  Alt 9. Feb 2011, 08:23
So vielleicht?

Delphi-Quellcode:
var
  f:TTextFile
begin
  AssignFile(...);
  if f<>nil then
  begin
    try
      //machwas
    finally
      CloseFile(...);
    end;
  end;
end;
Das ist doch wohl ziemlich unsinnig. Selbst wenn man außer acht läßt, daß es kein TTextfile gibt, ein Textfile kein Pointer ist etc: Wenn Du das AssignFile(...) aufrufst, dürfte die alte Verbindung ins Nirwana eingehen.

AssignFile(f) setzt TTextrec(f).Mode auf fmClosed, allerdings auch CloseFile. Reset/Rewrite etc setzen andere Werte der File mode constants. D.h. wenn TTextrec(f).Mode=fmClosed ist, kann man ziemlich sicher sein, daß f gerade nicht benutzt wird.

Zitat von Delphi-Hilfe:
File mode constants are used to open and close disk files.

Unit

System

Category

file management routines

const fmClosed = $D7B0; // closed file

const fmInput = $D7B1; // reset file (TTextRec)
const fmOutput = $D7B2; // rewritten file (TTextRec)
const fmInOut = $D7B3; // reset or rewritten file (TFileRec)
const fmCRLF = $8 // DOS-style EoL and EoF markers (TTextRec)
const fmMask = $D7B3; // mask out fmCRLF flag (TTextRec)

Description

Use the file mode constants when opening and closing disk files. The Mode field of TFileRec and TTextRec will contain one of these values.
  Mit Zitat antworten Zitat