Code: Select all
procedure CopyImageFromFile(FileName: String; Field: String; TargetTable: TZTable);
var
BlobStream: TStream;
FileStream: TStream;
b: TBookmark;
begin
with Form1 do
begin
if TargetTable.Active then
begin
ZQuery.SQL.Clear;
ZQuery.SQL.Add('BEGIN');
ZQuery.ExecSQL;
b := TargetTable.GetBookmark;
BlobStream := TargetTable.CreateBlobStream(
TargetTable.FieldByName(Field), bmWrite);
try
FileStream := TFileStream.Create(FileName, fmOpenRead);
try
BlobStream.CopyFrom(FileStream, FileStream.Size);
finally
FileStream.Free;
end;
finally
BlobStream.Free;
end;
TargetTable.Post;
ZQuery.SQL.Clear;
ZQuery.SQL.Add('COMMIT');
ZQuery.ExecSQL;
TargetTable.GotoBookmark(b);
TargetTable.Edit;
end;
end;
end;
After that last Edit, the TargetTable goes back into the dsInsert state.
Am I just doing this wrong?