Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#12

Re: filecreate produziert e/a-32

  Alt 23. Feb 2004, 10:05
Zitat von Toxman:
sicher gehen will, dass die Datei existiert und dann mit [..]
Also, ich löse das immer so:
Delphi-Quellcode:
constructor TTypedFile.Create(Filename : string);
var
  Data : TRecord;
begin
  AssignFile(f, Filename);
  { if exits open it }
  if FileExists(Filename) then
  begin
    //FileMode := fmShareExclusive;
    Reset(f);
  end
  { if not rewrite it }
  else
  begin
{$I-}
    Rewrite(f);
    if IOResult <> 0 then
    begin
      RaiseLastOSError;
{$I+}
      CloseFile(f);
      exit;
    end;
    FillChar(Data, sizeof(Data), #0);
    Data.Index := 0;
    { write the first emtpy record with the MaxID-Value }
    write(f, Data);
  end;
  { get the number of records }
  FRecordsCount := FileSize(f);
end;
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat