cxgrid直接载入图片

 

procedure TForm1.FormCreate(Sender: TObject);
var
 tmpMemStream: TMemoryStream;
 tmpPic: TPicture;
 tmpSize: LongInt;
 tmpStr,AFileName: String;
aa: TStringStream;

  AValue: AnsiString;
  APicture: TPicture;
begin
  ADOQuery1.Open;
// if not ADOTable1.Active then ADOTable1.Active:=True;
 //ADOTable1.first;
 
 while not ADOQuery1.eof do begin
    if not ADOQuery1.Fieldbyname('PrintFileName').IsNull then
   begin
   tmpMemStream := TMemoryStream.Create;
   tmpMemStream.LoadFromFile(ADOQuery1.Fieldbyname('PrintFileName').AsString);
   tmpSize := tmpMemStream.Size;
   SetLength(tmpStr, tmpSize);
   tmpMemStream.Read(tmpStr[1], tmpSize);
    tmpMemStream.Free;
   cxGrid1DBTableView1.DataController.SetValue(cxGrid1DBTableView1.DataController.RecNo-1, cxGrid1DBTableView1Column3.Index, tmpStr);
   end;
   ADOQuery1.Next;
end;
  
(*while not ADOQuery1.eof do
begin
  if not ADOQuery1.Fieldbyname('PrintFileName').IsNull then
  begin
    AFileName := ADOQuery1.Fieldbyname('PrintFileName').AsString;
    if FileExists(AFileName) then
    begin
      APicture := TPicture.Create;
      try
        APicture.LoadFromFile(AFileName);
        SavePicture(APicture, AValue);
      finally
        FreeAndNil(APicture);
      end;
    end
    else
      AValue := '';
      self.cxGrid1DBTableView1.DataController.Values[ADOQuery1.RecNo-1, cxGrid1DBTableView1Column3.Index] := AValue;
  end;
  ADOQuery1.Next;
 end;    *)

 

 

 

cxGrid1DBTableView1Column3为Variant类型,BlobEdit类型下拉列表。

你可能感兴趣的:(Delphi)