Einzelnen Beitrag anzeigen

Perlsau
(Gast)

n/a Beiträge
 
#2

AW: Blob field save AsString into DB

  Alt 6. Sep 2013, 09:48
What does this blob field represent? If you would fill a TMemo or a TRichEdit with the contents of this blob field, it would be okay. But if you want do represent a picture, a wave form or something like this it could be a problem to write/read it as string. Normally you read and write blob data by TFileStream or TMemoryStream:

Delphi-Quellcode:
function TDatMod.File_To_Blob(FileName: String; BlobFeld: TField): Boolean;
VAR
   S : TStream;
   FileS : TFileStream;

begin
     Result := FALSE;
     IF NOT FileExists(FileName) THEN EXIT;

     S := BlobFeld.DataSet.CreateBlobStream(BlobFeld, bmReadWrite);
     TRY
        FileS := TFileStream.Create(FileName, fmOpenRead);
        S.CopyFrom(FileS, FileS.Size);
        Result := TRUE;
     FINALLY
        FileS.Free;
        S.Free;
     END;
end;

function TDatMod.Blob_To_File(FileName: String; BlobFeld: TField): Boolean;
VAR
   S : TStream;
   FileS : TFileStream;

begin
     Result := FALSE;
     IF BlobFeld.IsNull THEN EXIT;

     S := BlobFeld.DataSet.CreateBlobStream(BlobFeld, bmRead);
     TRY
        FileS := TFileStream.Create(FileName, fmCreate);
        FileS.CopyFrom(S, S.Size);
        Result := TRUE;
     FINALLY
        S.Free;
        FileS.Free;
     END;
end;
  Mit Zitat antworten Zitat