var
aADOStream : _Stream;
aRS : _RecordSet;
iID : Integer;
vSQL : OleVariant;
begin
// Step 1: ADO-Stream-Objekt initialisieren
aADOStream := CoStream.Create;
aADOStream.Type_ := adTypeBinary;
aADOStream.Open(EmptyParam, adModeUnknown,
adOpenStreamUnspecified, '
', '
');
aADOStream.LoadFromFile(FFileName);
// Step 2: ADO-Recordset-Objekt initialisieren
aRS := CoRecordset.Create;
aRS.CursorLocation := adUseClient;
vSQL := RS_SQL;
aRS.Open(vSQL, ADOConnection1.ConnectionObject,
adOpenStatic, adLockOptimistic, adCmdText);
// Step 3: Neuen Datensatzpuffer anfordern
aRS.AddNew(EmptyParam, EmptyParam);
iID := StrToInt(EditID.Text);
// Step 4: Werte zuweisen, BLOb aus Stream-Objekt zuordnen
aRS.Fields.Item['
ID'].Value := iID;
aRS.Fields.Item['
FileContents'].Value := aADOStream.
Read(adReadAll);
// Step 5: Datensatz speichern
aRS.Update(EmptyParam, EmptyParam);
aRS.Close;
aADOStream.Close;
aRS :=
nil;
aADOStream :=
nil;
// Step 6: Datensatz zur Kontrolle neu einlesen
aRS := CoRecordset.Create;
vSQL := SELECT + IntToStr(iID);
aRS.Open(vSQL, ADOConnection1.ConnectionObject,
adOpenForwardOnly, adLockReadOnly, adCmdText);
// BLOb-Inhalt via Stream-Objekt auslesen und speichern
aADOStream := CoStream.Create;
aADOStream.Type_ := adTypeBinary;
aADOStream.Open(EmptyParam, adModeUnknown,
adOpenStreamUnspecified, '
', '
');
aADOStream.
Write(aRS.Fields.Item['
FileContents'].Value);
aADOStream.SaveToFile(FSaveFileName, adSaveCreateOverWrite);
aADOStream.Close;
aRS.Close;
Inc(iID);
EditID.Text := IntToStr(iID);
end;