dann kommt die fehlermeldung, dass das dataset nicht im editiermodus ist. aber was ich auch nicht verstehe, warum mein anderer buuton zum anlegen eines neuen datensatzes auch nicht funktioniert. hab nochmal den kompletten quelltext von dem programm reingestellt.
Delphi-Quellcode:
function JpegStartsInBlob(PicField:TBlobField):integer;
var
bS : TADOBlobStream;
buffer : Word;
hx : string;
begin
Result := -1;
bS := TADOBlobStream.Create(PicField, bmRead);
try
while (Result = -1) and (bS.Position + 1 < bS.Size) do begin
bS.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer,2);
if hx = 'FF' then begin
bS.ReadBuffer(buffer, 1);
hx:=IntToHex(buffer,2);
if hx = 'D8' then Result := bS.Position - 2
else if hx = 'FF' then bS.Position := bS.Position-1;
end;
end;
finally
bS.Free
end;
end;
procedure Tad.ADODataSet1AfterScroll(DataSet: TDataSet);
var
bS : TADOBlobStream;
Pic : TJpegImage;
begin
bS := TADOBlobStream.Create(AdoDataset1Bild, bmRead);
try
bS.Seek(JpegStartsInBlob(AdoDataset1Bild), soFromBeginning);
Pic:=TJpegImage.Create;
try
Pic.LoadFromStream(bS);
ADOImage.Picture.Graphic:=Pic;
finally
Pic.Free;
end;
finally
bS.Free
end;
end;
procedure Tad.Button1Click(Sender: TObject);
begin
if openpicturedialog1.Execute then
begin
AdoImage.Picture.LoadFromFile(openpicturedialog1.FileName);
end;
end;
procedure Tad.Button2Click(Sender: TObject);
var
blob: TAdoBlobStream;
fs:TMemorystream;
begin
AdoDataset1.edit;
blob := TADOBlobStream.Create(AdoDataset1Bild, bmwrite);
try
fs := TMemorystream.create();
ADOImage.Picture.Bitmap.SaveToStream(fs);
fs.Seek(0, soFromBeginning);
try
blob.CopyFrom(fs, fs.Size);
finally
fs.Free;
end;
finally
blob.Free;
AdoDataset1.post;
end;
end;
procedure Tad.Button3Click(Sender: TObject);
begin
adodataset1.append;
end;
procedure Tad.FormCreate(Sender: TObject);
var sDBPath, sCons: string;
begin
sDBPath := 'Desktop\Datenbank1.mdb';
sCons := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + sDBPath + ';Persist Security Info=False';
AdoDataset1.Active:=True;
end;
procedure Tad.FormDestroy(Sender: TObject);
begin
AdoDataset1.Active:=False;
end;
end.