Hello,
Here are two functions that copy to and from blob fields in delphi...
You will need to pass a valid field object and a full file path. Hopefully should point you in the right direction.
procedure TfrmSQLDocAdmin.SaveToSQL(AField: TField; AFile: TFileName);
var
bs : TStream;
fs : TFileStream;
strFileExt : string;
strFilePath : string;
strFileName : string;
begin
ADOTDocument.Insert;
AField.DataSet.Edit;
bs := AField.DataSet.CreateBlobStream(AField,bmWrite);
try
bs.Seek(0,soFromBeginning);
fs := TFileStream.Create(AFile,fmOpenRead);
try
bs.CopyFrom(fs,fs.Size);
finally
fs.Free
end;
finally
bs.Free
end;
strFileExt := ExtractFileExt(AFile);
strFilePath := ExtractFilePath(AFile);
strFileName := ExtractFileName(AFile);
with ADOTDocument do
begin
FieldByName('OrigDocName').Value := strFileName;
FieldByName('OrigDocPath').Value := strFilePath;
FieldByName('FileExt').Value := strFileExt;
Post;
end;
ShowMessage('Done');
end;
procedure TfrmSQLDocAdmin.LoadFromSQL(AField: TField; AFile: TFileName);
var
bs : TStream;
fs : TFileStream;
begin
bs := AField.DataSet.CreateBlobStream(AField,bmRead);
try
bs.Seek(0,soFromBeginning);
fs := TFileStream.Create(AFile,fmCreate);
try
fs.CopyFrom(bs,bs.Size);
finally
fs.Free
end;
finally
bs.Free
end;
ShowMessage('Done');
end;
There are two ways to write error-free programs; only the third one works.