Einzelnen Beitrag anzeigen

Perlsau
(Gast)

n/a Beiträge
 
#12

AW: Hilfe mit Delphi [idhttp.get error]

  Alt 1. Apr 2015, 10:04
Jupp, aber dann vor dem Try natürlich nicht das :=nil vergessen, denn sonst knallt auch noch das Free, da nicht initialisiert, wenn es im Create knallte.
Echt jetzt? Aprilscherz? In der Unit System wird doch bereits auf Nil geprüft und Destroy nur ausgeführt, wenn nicht Nil:
Delphi-Quellcode:
procedure TObject.Free;
begin
// under ARC, this method isn't actually called since the compiler translates
// the call to be a mere nil assignment to the instance variable, which then calls _InstClear
{$IFNDEF AUTOREFCOUNT}
  if Self <> nil then
    Destroy;
{$ENDIF}
end;
Und wird eine Objektvariable nicht automatisch bei der Deklaration mit Nil initialisiert? Oder muß ich das dann auch bereits vor dem ersten Try machen?
So dürfte es dann wohl hinhauen:
Delphi-Quellcode:
Function TDatMod.BlobFeldInDatei(Feld: TField; Datei: String): Boolean;
Var
  S : TStream;
  FileS : TFileStream;

begin
  Result := False;

  ...

  Try
    S := Feld.DataSet.CreateBlobStream(Feld, bmRead);
    FileS := TFileStream.Create(Datei, fmCreate);
    Try
      FileS.CopyFrom(S, S.Size);
      Result := True;
    Except
      on e:exception Do GLD.FehlerText := 'Fehler bei BlobToFile: ' + e.Message;
    End;
  Finally
    S.Free;
    FileS.Free;
  End;
end;
  Mit Zitat antworten Zitat