Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi filecreate produziert e/a-32 (https://www.delphipraxis.net/16753-filecreate-produziert-e-32-a.html)

dizzy 22. Feb 2004 23:21

Re: filecreate produziert e/a-32
 
Evtl. wartet Delphi bei "FileCreate" nicht auf dessen Fertigstellung (ist ne API-Fkt.), und geht einfach wieter im Code, und die Datei ist noch nicht "ganz fertig" wenn du schon reinschreiben willst. Aber bei "rewrite" wartet er schon. Klingt zumindest danach!

Luckie 23. Feb 2004 10:05

Re: filecreate produziert e/a-32
 
Zitat:

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;

th3lol 26. Dez 2005 17:20

Re: filecreate produziert e/a-32
 
was hälst du von FileClose?
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var k: integer;
begin
  k:=filecreate('Termine.txt');
  FileClose(k);
end;
filecreate(); übergibt das handle der erstellten datei und mit fileclose kannste dann die spezielle datei schließen. :-D

antwort kommt ein bisschen spät, aber ich hatte das selbe prob und deswegen hier mal für alle meine mitstreiter :P


Alle Zeitangaben in WEZ +1. Es ist jetzt 22:15 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz