Einzelnen Beitrag anzeigen

Gehstock

Registriert seit: 28. Jan 2006
Ort: Görlitz / Sachsen
489 Beiträge
 
Delphi 2007 Professional
 
#3

Re: teil einer datei entfernen

  Alt 4. Feb 2007, 13:04
das laden und speichern

Delphi-Quellcode:
procedure TConvertData.FBK2BINClick(Sender: TObject);
var
 iFHandle : THandle;
 iFileSize : Integer;
 iBytesRead: Integer;
 chBuffer: array[0..$3FFFF] of Byte;
begin
   iFHandle:=INVALID_HANDLE_VALUE;
   ProgressBar.Position:=10;
   with OpenDialog do begin
    FilterIndex:=1;
    InitialDir := '.';
    DefaultExt := 'fbk';
    Filter := 'Fbk files (*.fbk)|*.fbk|All files (*.*)|*.*';
    Options:=Options+[ofFileMustExist]-[ofHideReadOnly]
        +[ofNoChangeDir]-[ofNoLongNames]-[ofNoNetworkButton]-[ofHideReadOnly]
        -[ofOldStyleDialog]-[ofOverwritePrompt]+[ofPathMustExist]
        -[ofReadOnly]-[ofShareAware]-[ofShowHelp];
    Title:='Dateiauswahl FBK';
   end;//with OpenDialog
   if OpenDialog.execute then begin
    iFHandle:=FileOpen(OpenDialog.FileName,fmOpenRead or fmShareCompat);
    if iFHandle<>INVALID_HANDLE_VALUE then begin
      iFileSize:=$40000;
      iBytesRead := FileRead(iFHandle, chBuffer, iFileSize);
      FileClose(iFHandle);
      iFHandle:=INVALID_HANDLE_VALUE;
      if iBytesRead=iFileSize then begin
       ProgressBar.Position:=30;
       if ClearFBK(chBuffer[0]) then begin // aufruf Funktion
       exit;
        with SaveDialog do begin
         FilterIndex:=0;
         FileName := ExtractFileName(OpenDialog.FileName);
         InitialDir := ExtractFilePath(OpenDialog.FileName);
         DefaultExt := 'bin';
         Filter := 'bin files (*.bin)|*.bin';
         Options:=Options+[ofFileMustExist]-[ofHideReadOnly]
          +[ofNoChangeDir]-[ofNoLongNames]-[ofNoNetworkButton]-[ofHideReadOnly]
          -[ofOldStyleDialog]-[ofOverwritePrompt]+[ofPathMustExist]
          -[ofReadOnly]-[ofShareAware]-[ofShowHelp];
         Title:='Name der Bin Datei';
        end;//with
        ProgressBar.Position:=40;
        if SaveDialog.Execute then begin
         ProgressBar.Position:=60;
         iFHandle:=FileCreate(SaveDialog.FileName);
         if iFHandle<>INVALID_HANDLE_VALUE then begin
          ProgressBar.Position:=80;
          if FileWrite(iFHandle,chBuffer,$40000)=$40000 then begin
            FileClose(iFHandle);
            StatusBar.Panels[0].Text:='Datei gespeichert '+SaveDialog.FileName;
            ProgressBar.Position:=100;
            exit;
          end;
         end;
         StatusBar.Panels[0].Text:='Datei nicht gespeichert '+ SaveDialog.FileName+'!';
        end
        else begin
         StatusBar.Panels[0].Text:='?';
         if iFHandle<>INVALID_HANDLE_VALUE then FileClose(iFHandle);
         exit;
        end;
       end;
      end // if iBytesRead=iFileSize
      else begin
       StatusBar.Panels[0].Text:='Fehler beim lesen der Datei: '+OpenDialog.FileName+'!';
      end;
    end // if iFHandle>0
    else begin
     StatusBar.Panels[0].Text:='Kann Datei nicht öffnen '+OpenDialog.FileName+'!';
    end;
   end;
  if iFHandle<>INVALID_HANDLE_VALUE then FileClose(iFHandle);
end;
die Funktion
Delphi-Quellcode:
function TConvertData.ClearFBK(var buf : array of byte) : boolean;
begin
           result:=False;
          if (Dword((@buf[$000000])^) <> $014b4246)
           then begin
           StatusBar.Panels[0].Text:='Falsche Datei!';
           exit;
           end else
           StatusBar.Panels[0].Text:='Datei Ok!';
end;
hoffe das reicht
Marcel
  Mit Zitat antworten Zitat