Sometimes, a text field of a database table or query will be interpreted as a ftMemo blob, and the grid will show "(memo)" instead of the actual text.Quite annoying at times and I'm still surprised that this happens to remain unaddressed in both Lazarus and Delphi ...
Anyhoo .. how do we fix this?
Option 1 (easiest) - Modify your SQL Query
Now this option has the intend to make the "Memo Blob" look like a regular string. We can do this with a simply type cast.
Note : this might be slightly different, depending on your SQL Database. I have used this with SQLite, and MySQL, and heard it works in PostgreSQL as well.
Say your query is something like this:
SELECT
"Filename",
"Date"
FROM
"mytable";
And let's assume "Filename" is the offending field.
Now (make sure to remove the fields from the TQuery component!) change your query by casting the TEXT as a VARCHAR like so:
SELECT
CAST( "Filename" as VARCHAR) as "Filename",
"Date"
FROM
"mytable";
You will now see that the actual text is being displayed and not the "(memo)" text.
Option 2 - OnGetText Event
First we need to add fields to our TQuery. Right click the TQuery and select "Edit Fields".
In the upcoming window click the "+" button to at least add the field that shows as "(memo)".
Now click the newly added field. You'll see that a TMemoField has been added in the object inspector.
Click the "Events" tab in the object inspector and double click the "OnGetText" event.
Now add this code to the event handler (assuming: TQuery = qrySomeQuery, fieldname = "SomeField", which creates the TMemoField called "qrySomeQuerySomeField"):
aText := Sender.AsString;
DisplayText:=true;
So we get something like this, which now makes (at runtime) show the actual text instead if (memo):
procedure TForm1.qrySomeQuerySomeFieldGetText(Sender: TField; var aText: string; DisplayText: Boolean);
begin
aText := Sender.AsString;
DisplayText:=true;
end;