网淘巴来吧,欢迎您!

返回首页 微信
微信
手机版
手机版

FishFacts (Delphi)

2022-12-06 新闻来源:网淘巴 围观:330
''

描述:

下面的示例将T[文]able1或S[章]QLDataS[来]et1的Gra[自]phic字段中[网]的数据复制到C[淘]lientDa[巴]taSet1的[文]Picture[章]s字段。

代码:

var
  myBlobField : TBlobField;

procedure TForm1.CopyDataSourceClick(Sender: TObject);
var
  Stream1: TBlobStream;
  Stream2: TStream;
  blobType : TBlobType;
begin
  blobType := myBlobField.BlobType;
  DBImage2.DataField := 'Pictures';
  Stream1 := TBlobStream.Create(myBlobField, bmRead);
  try
    CDS2.Edit;
    { This is a different way to create a blob stream. }
    Stream2 := CDS2.CreateBlobStream(CDS2.FieldByName('Pictures'), bmReadWrite);
    try
      Stream2.CopyFrom(Stream1, Stream1.Size);
//    CDS2.Post;
//    CDS2.Active := True;
    finally
      Stream2.Free;
    end;
  finally
    Stream1.Free;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  I : Integer;
  S : String;
  ft : TFieldType;
  myString: String;
begin
// These properties can also be set statically at design time.
  Table1.DatabaseName := 'DBDEMOS';
  Table1.TableName := 'BioLife.DB';
  DataSource1.DataSet := Table1;
  DBGrid1.DataSource := DataSource1;
  Table1.Active := True; // Do this last
  myBlobField := nil;
  for I := 0 to Table1.FieldCount - 1 do
  begin
    S := Table1.Fields[I].FieldName;
    ft := Table1.Fields[I].DataType;
    case ft of
      ftFloat: myString := 'float';
      ftBoolean: myString := 'boolean';
      ftInteger: myString := 'integer';
      ftString: myString := 'string';
      ftCurrency: myString := 'currency';
      ftBlob:
      begin
        myString := 'blob';
        if (Table1.Fields[I] is TBlobField) then
          myBlobField := TBlobField(Table1.Fields[I]);
      end;
      ftSmallint: myString := 'smallint';
      ftTime: myString := 'time';
      ftDate: myString := 'date';
      ftDateTime: myString := 'datetime';
      ftTypedBinary: myString := 'typedBinary';
      ftMemo: myString := 'memo';
      ftGraphic: myString := 'graphic';
      ftAutoInc: myString := 'autoinc';
      else myString := 'unknown';
    end;
    ListBox1.Items.Add('Field ' + S + ' is of type: ' + myString);
  end;
  if (myBlobField <> nil) then
  begin
    with CDS2 do
    begin
      with FieldDefs.AddFieldDef do
      begin
        DataType := ftInteger;
        Name := 'Field1';
      end;
      with FieldDefs.AddFieldDef do
      begin
        DataType := ftBlob;
        Size := 10;
        Name := 'Pictures';
      end;
      with IndexDefs.AddIndexDef do
      begin
        Fields := 'Field1';
        Name := 'IntIndex';
      end;
      CreateDataSet;
//      DBMemo2.DataField := 'Remarks';
    end;
  end;
end;

 

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏

本文链接:https://www.wtao8.com/post/269.html 转载需授权!

分享到:

相关文章

龙年
大发