delphi TClientDataSet[20]: 使用 Blob 字段  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi TClientDataSet[20]: 使用 Blob 字段


TClientDataSet[20]: 使用 Blob 字段


Blob(Binary Large Object) 字段包括:

ftBlob, 

ftMemo, 

ftGraphic, 

ftFmtMemo, 

ftParadoxOle, 

ftDBaseOle, 

ftTypedBinary, 

ftCursor, 

ftFixedChar, 

ftWideString,

ftLargeint, 

ftADT, 

ftArray, 

ftReference, 

ftDataSet, 

ftOraBlob, 

ftOraClob, 

ftVariant, 

ftInterface, 

ftIDispatch, 

ftGuid, 

ftTimeStamp, 

ftFMTBcd, 

ftFixedWideChar, 

ftWideMemo


{ TBlobType = ftBlob..ftWideMemo }



示例:

20200814113733983.png



uses IOUtils, MMSystem;


{ 建立包含 Blob 字段的数据集, 并载入 Windows\Media\*.wav }

procedure TForm1.FormCreate(Sender: TObject);

var

  MediaPath, Path: string;

begin

  with ClientDataSet1 do begin

    FieldDefs.Add('WavFileName', ftString, 32);

    FieldDefs.Add('WAV', ftBlob);

    CreateDataSet;

  end;


  MediaPath := GetEnvironmentVariable('SystemRoot') + '\Media\';

  for Path in TDirectory.GetFiles(MediaPath, '*.wav') do

  begin

    ClientDataSet1.Append;

    ClientDataSet1['WavFileName'] := ExtractFileName(Path);

    TBlobField(ClientDataSet1.FieldByName('WAV')).LoadFromFile(Path);

  end;

  ClientDataSet1.MergeChangeLog;

end;


{ 播放 }

procedure TForm1.Button1Click(Sender: TObject);

var

  BlobStream: TClientBlobStream;

  BlobField: TBlobField;

begin

  BlobField := ClientDataSet1.FieldByName('WAV') as TBlobField;

  BlobStream := TClientBlobStream.Create(BlobField, bmRead);

  Win32Check(PlaySound(BlobStream.Memory, 0, SND_SYNC or SND_MEMORY));

  BlobStream.Free;

end;



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.03730320930481 seconds