I've always used TField / TParam variable shortcuts wherever possible so as to save multiple FieldByName / ParamByName lookups when dealing with multiple records. I'd prefer to keep doing that, but at the moment, the only to get the blob field populated seems to be via the ParamByName method for each record I want to create.
Code: Select all
procedure TClientData.CreatePart(const aFileName,aName:string ; const aId:integer);
var pId : TParam;
pName : TParam;
pPicture : TParam;
Stream : TFileStream;
begin
Stream := TFileStream.Create(aFileName,fmOpenRead);
LiteQuery.SQL.Clear;
LiteQuery.SQL.Add('insert into Part (Id,Name,Picture) values (:Id,:Name,:Picture)');
pId := LiteQuery.ParamByName('Id');
pName := LiteQuery.ParamByName('Name');
pPicture := LiteQuery.ParamByName('Picture');
pId.AsInteger := aId;
pName.AsString := aName;
// This works
// LiteQuery.ParamByName('Picture').LoadFromStream(Stream,ftBlob);
// This gives an access violation in TDAParam.GetIsNull
pPicture.LoadFromStream(Stream,ftBlob);
LiteQuery.Execute;
Stream.Free;
end;