2021年11月21日 星期日

ClientDataSet BLOB Binary Large Object TBlobField

 ClientDataSet  BLOB Binary Large Object   TBlobField

uses IOUtils, MMSystem;

  MediaPath, Path: string;

  with ClientDataSet1 do begin

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

    FieldDefs.Add('WAV', ftBlob);

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

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

    ClientDataSet1.Append;

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

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

  ClientDataSet1.MergeChangeLog;
 
  BlobStream: TClientBlobStream;

  BlobField: TBlobField;

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

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

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

  BlobStream.Free;

 

    01.DataSetProvider.Options.poPropogateChanges:=True;  
    02.procedure TForm1.DataSetProvider1AfterUpdateRecord(Sender: TObject;  
    03.SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;  
    04.UpdateKind: TUpdateKind);  
    05.begin  
    06.//DstId TADODataset  
     07.//FId self-growth fields  
    08.if   UpdateKind=ukInsert then  
    09.    begin  
    10.       DstId.CommandText:='select @@Identity as FId ';  
    11.       DstId.Open;  
    12.       DeltaDS.FieldByName('FId').ReadOnly:=False;  
    13.       DeltaDS.FieldByName('FId').NewValue:=DstId.FieldByName('FId').AsInteger ;  
    14.       DstId.Close;  
    15.   end;  
    16.end;  
01.procedure TProducts.DataSetProvider1BeforeUpdateRecord(Sender: TObject;  
02.SourceDS: TDataSet; DeltaDS: TCustomClientDataSet;  
03.UpdateKind: TUpdateKind; var Applied: Boolean);  
04.begin  
05.//DstProduct from the table Name  
 06.//CategoryID from the associated field of the table for the word from the segment by a primary table  
 07.// qryIdentity is TADOQuery qryIdentity.SQL: = 'select @@ identity'  
08.if (UpdateKind = ukInsert) and  
09.(SourceDS = DstProduct) and  
10.(DeltaDS.FieldByName('CategoryID').Value = Unassigned)   ) then  
11.begin  
12.    if DeltaDS.BOF then  
13.    begin  
14.      qryIdentity.Close;  
15.      qryIdentity.Open;  
16.    end;  
17.    DeltaDS.FieldByName('CategoryID').NewValue := qryIdentity.Fields[0].Value;  
18.end;  
19.end;  
 

沒有留言: