Obrazek z TImage do pola BLOB poprzez ADOCommand i parametr

0

Witam.
Ja już zgłupiałem. Potrzebuję uaktualnić w tabeli rekord. W tym rekordzie jest między innymi pole typu BLOB przechowujące zdjęcie. Mam ADOCommand z wpisanym sparametryzowanym zapytaniem. Następnie przypisuję parametrom wartości. Z tymże mam w TImage zdjęcie pobrane wcześniej z tego rekordu.
Może wkleję kod, łatwiej będzie załapać:

with Dane.acmdUaktualnijZwierze.Parameters do
begin
  ParamByName('plecu').Value := dblcbPlec.KeyValue;
  ParamByName('rozmiaru').Value := edtRozmiar.Text;
  ParamByName('mascu').Value := dblcbMasc.KeyValue;
  ParamByName('chipu').Value := edtChip.Text;
  ParamByName('data_przyjeciau').Value := DateToStr(DateTimePicker1.Date);
  ParamByName('szczegoly_przyjeciau').Value := Memo1.Text;
  if CheckBox1.Checked then
  begin
    ParamByName('data_wyjsciau').Value := DateToStr(DateTimePicker2.Date);
    ParamByName('opis_wyjsciau').Value := Memo2.Text;
    ParamByName('sposob_wyjsciau').Value := dblcbSposobyWyjscia.KeyValue;
  end else
  begin
    ParamByName('data_wyjsciau').Value := NULL;
    ParamByName('opis_wyjsciau').Value := NULL;
    ParamByName('sposob_wyjsciau').DataType := ftInteger;
    ParamByName('sposob_wyjsciau').Value := NULL;
  end;
  if edtPicture.Text <> '' then
  begin
    ParamByName('zdjecieu').LoadFromFile(edtPicture.Text, ftBlob);
  end else
  begin
    imgZdjecie.Picture.Graphic.SaveToStream(s);
    ParamByName('zdjecieu').LoadFromStream(s, ftBlob);
  end;
  ParamByName('klientu').Value := dblcbClient.KeyValue;
  ParamByName('lokacjau').Value := dblcbLocalization.KeyValue;
  if CheckBox1.Checked then
  begin
    ParamByName('stanu').Value := 'N';
  end else
  begin
    ParamByName('stanu').Value := 'Y';
  end;
  ParamByName('typu').Value := dblcbAnimalType.KeyValue;
  ParamByName('identu').Value := edtID.Text;
  ParamByName('idu').Value := id;
end;
Dane.acmdUaktualnijZwierze.Execute;

No i nie wiem czemu, ale się wykłada. Może jakaś dobra dusza podpowie co mam zrobić?

0

ADOCommand.Parameters.ParamByName('parametr').LoadFromStream(Stream, ftGraphic);

0

A czemu wykłada się to:

  begin
    s := TStream.Create;
    imgZdjecie.Picture.Graphic.SaveToStream(s);
    ParamByName('zdjecieu').LoadFromStream(s, ftGraphic);
  end;

s jest zadeklarowane jako TStream. Przy zapisie TImage do TStream, dostaję błąd "Abstract Error".

Natomiast, gdy zrobię coś takiego:

  begin
    s := TStream.Create;
    imgZdjecie.Picture.Bitmap.SaveToStream(s);
    ParamByName('zdjecieu').LoadFromStream(s, ftGraphic);
  end;

otrzymuję komunikat TStream.Seek not implemented.

Ktoś coś wie na ten temat??

0
Buster napisał(a)

Ktoś coś wie na ten temat??

tak, np. help
poczytaj sobie co to jest i po co klasa abstrakcyjna

0

No i przeczytałem i nie jestem odrobinę mądrzejszy. Nadal kompletnie nie wiem jak się do tego zabrać. Nie wiem jak poprzez strumień przepisać obrazek z TImage, konkretnie do parametru w TADOCommand poprzez ParamByName. Faktycznie jest tam metoda LoadFromStream. W porządku, ale jak zapisać TImage do strumienia, to ja już niestety nie wiem. I wychodzi, że jestem głąb patentowany.

0

zaznaczyłem Ci co ważniejsze miejsca

Delphi help napisał(a)

TStream

TStream is the base class type for stream objects that can read from or write to various kinds of storage media, such as disk files, dynamic memory, and so on.

Unit

Classes

Description

Use specialized stream objects to read from, write to, or copy information stored in a particular medium. Each descendant of TStream implements methods for transferring information to and from a particular storage medium, such as a disk file, dynamic memory, and so on. In addition to methods for reading, writing, and copying bytes to and from the stream, stream objects permit applications to seek to an arbitrary position in the stream. Properties of TStream provide information about the stream, such as its size and the current position in the stream.

TStream also introduces methods that work in conjunction with components and filers for loading and saving components in simple and inherited forms. These methods are called automatically by global routines that initiate component streaming. They can also be called directly to initiate the streaming process. Note, however, that component streaming always involves two additional objects:

    A component object that is passed as a parameter to the stream’s methods.

A filer object that is automatically created by the stream, and associated with the stream.

TStream is an abstract or, in C++ terminology, pure virtual class. It should not be instantiated; it relies on abstract or pure virtual methods that must be overridden in descendant classes. Descendant stream objects, such as memory and file streams used for component streaming, are created automatically by the global functions ReadComponentRes and WriteComponentRes. For streaming other kinds of information, choose a descendant class according to the specific data and storage needs. These include

    <b>TFileStream (for working with files)

TStringStream (for manipulating in-memory strings)
TMemoryStream (for working with a memory buffer)
TBlobStream (for working with BLOB fields)
TWinSocketStream (for reading and writing over a socket connection)
TOleStream (for using a COM interface to read and write)</b>

0

Witam, zamieszczam działający kawałek kodu, przerób sobie na własne potrzeby.

procedure TForm1.Button1Click(Sender: TObject);
var
 obraz: TMemoryStream;
begin

 obraz:=TMemoryStream.Create;
 Image1.Picture.Graphic.SaveToStream(obraz);

  Query.Close;
  Query.SQL.Clear;
  Query.SQL.Add('insert into foto (obraz)values(:OBRAZ)');
  Query.UnPrepare;
  Query.ParamByName('OBRAZ').LoadFromStream(obraz,ftBlob);
// można też
// Query.ParamByName('OBRAZ').SetBlobData(obraz.Memory,obraz.Size);
  Query.Prepare;
  Query.ExecSQL;

 obraz.Free;

end;
0

Witam

To jeszcze pod ten temat podepnę jedno pytanko. Nie mogę sobie poradzić z wyświetleniem obrazka z pola typu blob.

Zapis robię tak (bez obsługi błędów i zarz. pamięcią - dla czytelności):

LogoMS := TMemoryStream.Create;
Logo.Graphics.SaveToStream(LogoMS); // Logo : TcxImage.Pictrue;
parambyname('LOGO').LoadFromStream(LogoMS, ftBlob);

No i chyba się zapisuje bo się nie wywala (jak dałem ftGraphics to dostałem Exceptiona Feature not supported)

No i teraz chciałbym z powrotem do tego TcxImage wyciągnąć tego blob'a, najlepiej bez użycia SaveToFile i LoadFromFile, no i jak to zrobić ? Jak robię tak to dostaje AV : (

LogoMS := TMemoryStream.Create;
WybranyQLOGO.SaveToStream(LogoMS); // WybranyQLOGO : TBlobField;
LogoI.Picture.Graphic.LoadFromStream(LogoMS); // LogoI : TcxImage;
LogoMS.Free;

Używam IBX'ów i FB1.5

0

W sumie działa tak:

blob := CreateBlobStream(FieldByName('LOGO'), bmRead); // blob : TStream;
LogoI.Picture.Bitmap.LoadFromStream(blob); // LogoI : TImage

Ale tylko dla bmp'ków a ja bym chciał żeby działało dla każdego rodzaju grafik.

1 użytkowników online, w tym zalogowanych: 0, gości: 1