Thema: Delphi TFileStream Fehler ???

Einzelnen Beitrag anzeigen

jonny

Registriert seit: 15. Dez 2003
235 Beiträge
 
Delphi 7 Enterprise
 
#1

TFileStream Fehler ???

  Alt 8. Mär 2004, 22:28
Hallo alle zusammen.
Ich schreibe ein Programm für Videoarchivierung und möchte gerne einzelne Filme importieren und exportieren zu können.
Habe dazu folgende zwei Prozeduren aber es klappt nicht ich bekomme immer einen Fehler und zwar beim Importieren. Der Fehler Lautet: Fehler beim lesen von Adresse ....... usw.

Delphi-Quellcode:
procedure TForm1.ExportMovieData(FileName: String);
var FS: TFileStream;
    Titel: String;

  procedure WriteString(S: String);
  var Laenge: Integer;
  begin
    Laenge:=Length(S);
    FS.Write(Laenge, SizeOf(Laenge));
    FS.Write(S, Laenge);
  end;

  procedure WriteInt(Int: Integer);
  begin
    FS.Write(Int, SizeOf(Int));
  end;

  procedure WriteStream(Blob: TBlobField);
  var Laenge: Integer;
      Strm: TMemoryStream;
  begin
    Strm:=TMemoryStream.Create;
    Strm.Clear;
    Blob.SaveToStream(Strm);
    Laenge:=Strm.Size;
    Strm.Position:=0;
    FS.Write(Laenge, SizeOf(Laenge));
    If Laenge > 0 Then
      FS.CopyFrom(Strm, Laenge);
    Strm.Free;
  end;

begin
  FS:=TFileStream.Create(FileName, fmCreate);

  WriteString(ClientDataSet1.FieldByName('Titel').AsString);
  WriteString(ClientDataSet1.FieldByName('Beschreibung').AsString);
  WriteString(ClientDataSet1.FieldByName('Genre').AsString);
  WriteString(ClientDataSet1.FieldByName('Filmformat').AsString);
  WriteInt(ClientDataSet1.FieldByName('Produktionsjahr').AsInteger);
  WriteString(ClientDataSet1.FieldByName('Produktionsland').AsString);
  WriteInt(ClientDataSet1.FieldByName('Filmlaenge').AsInteger);
  WriteString(ClientDataSet1.FieldByName('Bildformat').AsString);
  WriteString(ClientDataSet1.FieldByName('Darsteller').AsString);
  WriteString(ClientDataSet1.FieldByName('Regie').AsString);
  WriteString(ClientDataSet1.FieldByName('Sprachen').AsString);
  WriteString(ClientDataSet1.FieldByName('Filmgesellschaft').AsString);
  WriteString(ClientDataSet1.FieldByName('URL').AsString);
  WriteString(ClientDataSet1.FieldByName('FSK').AsString);
  WriteStream(TBlobField(ClientDataSet1.FieldByName('Bild1')));
  WriteStream(TBlobField(ClientDataSet1.FieldByName('Bild2')));
  WriteStream(TBlobField(ClientDataSet1.FieldByName('Bild3')));
  WriteStream(TBlobField(ClientDataSet1.FieldByName('Bild4')));

  FS.Free;
end;

procedure TForm1.ImportMovieData(FileName: String);
var FS: TFileStream;
    MyStream: TStream;

  function ReadString: String;
  var Laenge: Integer;
  begin
    Result:='';
    FS.Read(Laenge, SizeOf(Laenge));
    FS.Read(Result, Laenge);
  end;

  function ReadInt: Integer;
  begin
    Result:=0;
    FS.Read(Result, SizeOf(Result));
  end;

  procedure ReadStream(Strm: TStream);
  var Laenge: Integer;
  begin
    FS.Read(Laenge, SizeOf(Laenge));
    If Laenge > 0 Then
      Strm.CopyFrom(FS, Laenge)
    else
      Strm:=nil;
  end;

begin
  FS:=TFileStream.Create(FileName, fmOpenRead OR fmShareDenyNone);
  FS.Position:=0;
  ClientDataSet1.Insert;

  ClientDataSet1.FieldByName('Titel').AsString:=ReadString;
  ClientDataSet1.FieldByName('Beschreibung').AsString:=ReadString;
  ClientDataSet1.FieldByName('Genre').AsString:=ReadString;
  ClientDataSet1.FieldByName('Filmformat').AsString:=ReadString;
  ClientDataSet1.FieldByName('Produktionsjahr').AsInteger:=ReadInt;
  ClientDataSet1.FieldByName('Produktionsland').AsString:=ReadString;
  ClientDataSet1.FieldByName('Filmlaenge').AsInteger:=ReadInt;
  ClientDataSet1.FieldByName('Bildformat').AsString:=ReadString;
  ClientDataSet1.FieldByName('Darsteller').AsString:=ReadString;
  ClientDataSet1.FieldByName('Regie').AsString:=ReadString;
  ClientDataSet1.FieldByName('Sprachen').AsString:=ReadString;
  ClientDataSet1.FieldByName('Filmgesellschaft').AsString:=ReadString;
  ClientDataSet1.FieldByName('URL').AsString:=ReadString;
  ClientDataSet1.FieldByName('FSK').AsString:=ReadString;

  MyStream:=ClientDataSet1.CreateBlobStream(Form1.ClientDataSet1.FieldByName('Bild1'), bmReadWrite);
  ReadStream(MyStream);
  MyStream.Free;
  MyStream:=ClientDataSet1.CreateBlobStream(Form1.ClientDataSet1.FieldByName('Bild2'), bmReadWrite);
  ReadStream(MyStream);
  MyStream.Free;
  MyStream:=ClientDataSet1.CreateBlobStream(Form1.ClientDataSet1.FieldByName('Bild3'), bmReadWrite);
  ReadStream(MyStream);
  MyStream.Free;
  MyStream:=ClientDataSet1.CreateBlobStream(Form1.ClientDataSet1.FieldByName('Bild4'), bmReadWrite);
  ReadStream(MyStream);
  MyStream.Free;
  ClientDataSet1.Post;

  FS.Free;
end;
  Mit Zitat antworten Zitat