I forgot about the source of this, but this is what I do with the memo fields in tdbgrid. bluish is right about the gettext event, this is how to implement it in code:
Create a class called MemoDifier:
MemoDifier = class public procedure DBGridOnGetText(Sender: TField; var aText: string; DisplayText: boolean); end;
In the implementation section of your code, put this:
procedure MemoDifier.DBGridOnGetText(Sender: TField; var aText: string; DisplayText: boolean); begin if (DisplayText) then aText := Sender.AsString; end;
Then click the tdbgrid control in your form and in the object inspector (Lazarus IDE), go to the "Events" tab, scroll down the page below to find the OnPrepareCanvas event. Double click it to generate the code. Then change the code according to your needs, for example, the name of your tdbgrid control:
procedure Tmainui.TDBGrid1PrepareCanvas(sender: TObject; DataCol: Integer; Column: TColumn; AState: TGridDrawState); var MemoFieldReveal: MemoDifier; begin if (DataCol = 1) then begin try TDBGrid1.Columns.Items[0].Field.OnGetText := @MemoFieldReveal.DBGridOnGetText; TDBGrid1.Columns.Items[1].Field.OnGetText := @MemoFieldReveal.DBGridOnGetText; TDBGrid1.Columns.Items[2].Field.OnGetText := @MemoFieldReveal.DBGridOnGetText; except On E: Exception do begin ShowMessage('Exception caught : ' + E.Message); end; end; end; end;
The MemoFieldReveal variable points to the MemoDifier class. Remember to change the index (Items [x]) to indicate your index number of the tdbgrid elements / fields that the text (MEMO) shows.
Allan registos
source share