



O Field do tipo Blob é muito utilizado para registro de Obsservações, por exemplo.
Porém ao simplesmente vincular o DataSet ao DBGrid, o mesmo exibe (Blob) na
coluna.
Para contornar este problema, existe duas formas:
Caso o Field esteja declarado, podemos fazer assim
No Evento OnGetText do Field:
1 2 3 4 5 | procedure TForm1.ClientDataSet1OBSERVACAOGetText(Sender: TField; var Text: string; DisplayText: Boolean); begin Text := Sender.AsString; end; |
Caso o Field Não esteja declarado, também é possível, só temos um
pouco mais de trabalho:
Criando uma procedure e vinculando ao evento do Field pelo código.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, strutils, Data.DB, Datasnap.DBClient; type TForm1 = class(TForm) Button1: TButton; ClientDataSet1: TClientDataSet; ClientDataSet1OBSERVACAO: TBlobField; procedure ClientDataSet1BeforeOpen(DataSet: TDataSet); private procedure GetTextBlob(Sender: TField; var Text: string; DisplayText: Boolean); public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.ClientDataSet1BeforeOpen(DataSet: TDataSet); begin ClientDataSet1.FieldByName('OBSERVACAO').OnGetText := GetTextBlob; end; procedure TForm1.GetTextBlob(Sender: TField; var Text: string; DisplayText: Boolean); begin Text := Sender.AsString; end; end. |
Espero que seja útil pessoal!
Dúvidas ou sugestões, deixe nos comentários do post.