Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Read And Write A Blob Field Using FireDAC

Discussion in 'Delphi Android And IOS' started by N0body, Feb 28, 2014.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator Staff Member DF Staff

    If you’re using the FireDAC components that comes with Delphi XE5 Firemonkey and you want to save a bitmap or some other type of data to a blog field on your embedded database (either SQLite, IBlite, or Interbase To Go) it can be a bit tricky. For saving it is pretty standard fair with the TFDDataSet.LoadFromStream() which will load a stream like a memory stream into a field. The important piece to reading the blob back out is is the TFDDataSet.CreateBlobStream() function. I have included two functions below which show an example of how to read and write a string and bitmap data from an image using a FireDAC TFDQuery component. This method of reading and writing a blog works on Android and IOS as well as Windows and OSX.


    Code:
    procedure SaveToFireDACBlob;
    var
    MemStream: TMemoryStream;
    begin
    FireDAC.Connected := True;
    MemStream := TMemoryStream.Create;
    try
    Image1.Bitmap.SaveToStream(MemStream);
    MemStream.Seek(0,0);
    FDQueryInsert.ParamByName(‘Media’).LoadFromStream(MemStream,ftBlob);
    FDQueryInsert.ParamByName(‘MType’).AsString := ’0′;
    FDQueryInsert.ExecSQL();
    except
    on e: Exception do
    begin
    //ShowMessage(e.Message);
    end;
    end;
    MemStream.Free;
    FireDAC.Connected := False;
    end;
    
    procedure LoadFromFireDACBlob;
    var
    BlobStream: TStream;
    begin
    FireDAC.Connected := True;
    try
    FDQuerySelect.Open;
    FDQuerySelect.First;
    while(not FDQuerySelect.EOF)do begin
    // access a stream from a blog like this
    BlobStream := FDQuerySelect.CreateBlobStream(FDQuerySelect.FieldByName(‘Media’),TBlobStreamMode.bmRead);
    // access a string from a field like this
    if (FDQuerySelect.FieldByName(‘MType’).AsString=’0′) then
    begin
    // load your blob stream data into a control
    ImageViewer.Bitmap.LoadFromStream(BlobStream);
    end;
    BlobStream.Free;
    FDQuerySelect.Next;
    end;
    except
    on e: Exception do
    begin
    //ShowMessage(e.Message);
    end;
    end;
    FireDAC.Connected := False;
    end;
    

    More in this site
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block