<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Lazarus - How to fix a Database field showing as (memo) in a DBGrid - Delphi, Lazarus, Free Pascal				            </title>
            <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Tue, 21 Jul 2026 01:55:59 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: Lazarus - How to fix a Database field showing as (memo) in a DBGrid</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6143</link>
                        <pubDate>Fri, 10 Oct 2025 18:39:38 +0000</pubDate>
                        <description><![CDATA[Hello!
Thank you very much for your time and help. I must learn more SQL. Thanks.]]></description>
                        <content:encoded><![CDATA[<p>Hello!</p>
<p>Thank you very much for your time and help. I must learn more SQL. Thanks.</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Anonymous</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6143</guid>
                    </item>
				                    <item>
                        <title>RE: Lazarus - How to fix a Database field showing as (memo) in a DBGrid</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6140</link>
                        <pubDate>Wed, 08 Oct 2025 20:29:33 +0000</pubDate>
                        <description><![CDATA[@pcavenida I&#039;m afraid you have to learn a few things about how this works - you&#039;re probably very new to Lazarus Pascal, so let me see if I can help.
1) The screenshot you&#039;re showing is wher...]]></description>
                        <content:encoded><![CDATA[<p>@pcavenida I'm afraid you have to learn a few things about how this works - you're probably very new to Lazarus Pascal, so let me see if I can help.</p>
<p><span style="color: #0000ff">1) The screenshot you're showing is where <strong><em>only</em> SQL code</strong> is placed.</span></p>
<p>So no Pascal here, just SQL. This can only be done in the IDE, do during development (at <strong>design time</strong>) when you gave access to the Object Inspector (the window on the left where you can change all kinds of properties like the SQL property which brings up the window in our screenshot).</p>
<p>In my previous example that would be (so paste this in the editor in your screenshot):</p>
<pre contenteditable="false">SELECT
CAST( "ClienteNome" as CHAR ) as "ClienteNome",
SUBSTR( "ClienteNome",1,10) as "ClienteNomeShort"
FROM
"Clientes";</pre>
<p><span style="color: #0000ff">2) The code you pasted is actual <strong>Pascal code</strong>, which should not be pasted there.</span></p>
<p>Instead you use that in the IDE code editor, where you'll find all your Pascal code, for example on the OnCreate event of the form, or the OnClick event of a button. This code is executed <strong>only at run time</strong>, so after you compiled your program.<br />This would allow you to change the query at run time if needed, but you will not see any result until you run the program.</p>
<p>This would be the second code example, which is where in Pascal you pass SQL code to the TSQLQuery.</p>
<pre contenteditable="false">...
  mySLQQuery : TSQLQuery;
...
  mSQLQuery.SQL.Text := 
    'SELECT '+
    'CAST( "ClienteNome" as CHAR ) as "ClienteNome", '+
    'SUBSTR( "ClienteNome",1,10) as "ClienteNomeShort" '+
    'FROM "Clientes"';
...</pre>
<p>&nbsp;</p>
<p>Hope this helps &#x1f60a; </p>
<p>p.s. if you want to know more on topics like this, consider starting a new topic for each specific problem. This way topics stay on specific questions which makes it easier for other to find answer when they run into similar problems &#x1f609;  </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6140</guid>
                    </item>
				                    <item>
                        <title>RE: Lazarus - How to fix a Database field showing as (memo) in a DBGrid</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6139</link>
                        <pubDate>Wed, 08 Oct 2025 18:34:19 +0000</pubDate>
                        <description><![CDATA[Hello!! Again.
I put your code in Lazarus like you can see in the atached files. It gives an syntax error. Can you help? Thank you.

&nbsp;
&nbsp;]]></description>
                        <content:encoded><![CDATA[<p>Hello!! Again.</p>
<p>I put your code in Lazarus like you can see in the atached files. It gives an syntax error. Can you help? Thank you.</p>
781
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Anonymous</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6139</guid>
                    </item>
				                    <item>
                        <title>RE: Lazarus - How to fix a Database field showing as (memo) in a DBGrid</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6133</link>
                        <pubDate>Tue, 07 Oct 2025 17:49:48 +0000</pubDate>
                        <description><![CDATA[You added &quot;;&quot; at the end of the 2nd and 3rd line of the SQL statements. That won&#039;t work.The proper SQL statement would be (replace the first &quot;;&quot; with a &quot;,&quot; and remove the second &quot;;&quot;) somethi...]]></description>
                        <content:encoded><![CDATA[<p>You added "<strong>;</strong>" at the end of the 2nd and 3rd line of the SQL statements. That won't work.<br />The proper SQL statement would be (replace the first "<strong>;</strong>" with a "<strong>,</strong>" and remove the second "<strong>;</strong>") something like this.<br />It is recommended to use two different field names (you used "<strong>ClienteNome</strong>" for both fields, which leads to confusion).</p>
<pre contenteditable="false">SELECT
CAST( "ClienteNome" as CHAR ) as "ClienteNome",
SUBSTR( "ClienteNome",1,10) as "ClienteNomeShort"
FROM
"Clientes";</pre>
<p>Not sure what you meant with "in Lazarus", so I assume you either pasted it in the SQL property, or you did something like this in code:</p>
<pre contenteditable="false">...
  mySLQQuery : TSQLQuery;
...
  mSQLQuery.SQL.Text := 
    'SELECT '+
    'CAST( "ClienteNome" as CHAR ) as "ClienteNome", '+
    'SUBSTR( "ClienteNome",1,10) as "ClienteNomeShort" '+
    'FROM "Clientes"';
...</pre>
<p>Hope this help &#x1f609; </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6133</guid>
                    </item>
				                    <item>
                        <title>RE: Lazarus - How to fix a Database field showing as (memo) in a DBGrid</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6132</link>
                        <pubDate>Tue, 07 Oct 2025 17:18:54 +0000</pubDate>
                        <description><![CDATA[Hi!
Thank you very much for your help.
Can you say where and how I can put the 2 SQL instrutions?
I put in Lazarus like these. But not working:
&nbsp;
SELECT
CAST( &quot;ClienteNome&quot; as CHA...]]></description>
                        <content:encoded><![CDATA[<p>Hi!</p>
<p>Thank you very much for your help.</p>
<p>Can you say where and how I can put the 2 SQL instrutions?</p>
<p>I put in Lazarus like these. But not working:</p>
<p>&nbsp;</p>
<pre contenteditable="false">SELECT
CAST( "ClienteNome" as CHAR ) as "ClienteNome";
SUBSTR( "ClienteNome",1,10) as "ClienteNome";
FROM
"Clientes";</pre>
<p>Can you help? Again?</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Anonymous</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6132</guid>
                    </item>
				                    <item>
                        <title>RE: Lazarus - How to fix a Database field showing as (memo) in a DBGrid</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6123</link>
                        <pubDate>Sun, 05 Oct 2025 09:10:37 +0000</pubDate>
                        <description><![CDATA[@pcavenida Welcome!
You can cut down the field length in SQL by using SUBSTR, example:
SELECT SUBSTR (&#039;Some long text that we want to cut down to 10 characters&#039;, 1,10);
which results in (...]]></description>
                        <content:encoded><![CDATA[<p>@pcavenida Welcome!</p>
<p>You can cut down the field length in SQL by using SUBSTR, example:</p>
<pre contenteditable="false">SELECT SUBSTR ('Some long text that we want to cut down to 10 characters', 1,10);</pre>
<p>which results in (without the double quotes of course):</p>
<pre contenteditable="false">"Some long "</pre>
<p>So in the example above, you'd use something like this:</p>
<pre contenteditable="false">SELECT
  SUBSTR( "Filename",1,10) as "ShortFilename", 
  "Date"
FROM
  "mytable";</pre>
<p>Hope this helps &#x1f60a; </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6123</guid>
                    </item>
				                    <item>
                        <title>RE: Lazarus - How to fix a Database field showing as (memo) in a DBGrid</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6118</link>
                        <pubDate>Sat, 04 Oct 2025 17:41:41 +0000</pubDate>
                        <description><![CDATA[Hello!
I´m new to this forum...:)
Can you help me in the first example in SQL. The size of the field is to long. And I want that the field be the size of 10 Characters long. How can I do t...]]></description>
                        <content:encoded><![CDATA[<p>Hello!</p>
<p>I´m new to this forum...:)</p>
<p>Can you help me in the first example in SQL. The size of the field is to long. And I want that the field be the size of 10 Characters long. How can I do this in SQL?</p>
<p>&nbsp;</p>
<p>Thank you very much.</p>
<p>&nbsp;</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Anonymous</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-6118</guid>
                    </item>
				                    <item>
                        <title>RE: Lazarus - How to fix a Database field showing as (memo) in a DBGrid</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-5861</link>
                        <pubDate>Thu, 12 Jun 2025 07:42:37 +0000</pubDate>
                        <description><![CDATA[Thank you for chiming in ... &#x1f60a; 
In SQLite the TEXT field can be either text or even a binary blob. I wish Lazarus Pascal would just have a property TFields that allows one to toggle...]]></description>
                        <content:encoded><![CDATA[<p>Thank you for chiming in ... &#x1f60a; </p>
<p>In SQLite the TEXT field can be either text or even a binary blob. <br />I wish Lazarus Pascal would just have a property TFields that allows one to toggle it to actual text (VARCHAR).<br />All the work-arounds are rather cumbersome when working on projects with a lot of data.</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-5861</guid>
                    </item>
				                    <item>
                        <title>RE: Lazarus - How to fix a Database field showing as (memo) in a DBGrid</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-5859</link>
                        <pubDate>Wed, 11 Jun 2025 03:13:03 +0000</pubDate>
                        <description><![CDATA[If you&#039;re seeing (memo) in your DBGrid instead of the actual content, it&#039;s likely because the field type in your dataset is a Memo (or TEXT/CLOB depending on your DBMS), which DBGrid doesn&#039;t...]]></description>
                        <content:encoded><![CDATA[<p data-start="139" data-end="412">If you're seeing <strong data-start="156" data-end="166">(memo)</strong> in your DBGrid instead of the actual content, it's likely because the field type in your dataset is a <strong data-start="269" data-end="277">Memo</strong> (or <code data-start="282" data-end="288">TEXT</code>/<code data-start="289" data-end="295">CLOB</code> depending on your DBMS), which DBGrid doesn't display fully by default due to potential performance and size issues.</p>
<h3 data-start="414" data-end="444">Here's how you can fix it:</h3>
<ol data-start="446" data-end="1100">
<li data-start="446" data-end="811">
<p data-start="449" data-end="574"><strong data-start="449" data-end="475">Use a calculated field</strong>:<br data-start="476" data-end="479" />Create a calculated field in your dataset that extracts a short preview of the memo content.</p>
<div class="contain-inline-size rounded-2xl border- border-token-border-medium relative bg-token-sidebar-surface-primary">
<div class="flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-2xl"> </div>
<div class="sticky top-9"> </div>
<div class="overflow-y-auto p-4" dir="ltr"><code class="whitespace-pre! language-pascal"><span>procedure TForm1.ClientDataSet1CalcFields(DataSet: TDataSet);
begin
  ClientDataSet1.FieldByName('MemoPreview').AsString := 
    Copy(ClientDataSet1.FieldByName('YourMemoField').AsString, 1, 100);
end;
</span></code></div>
</div>
</li>
<li data-start="813" data-end="920">
<p data-start="816" data-end="920"><strong data-start="816" data-end="848">Assign it to a DBGrid column</strong>:<br data-start="849" data-end="852" />Add <code data-start="859" data-end="872">MemoPreview</code> to the grid instead of the original memo field.</p>
</li>
<li data-start="922" data-end="1100">
<p data-start="925" data-end="1100"><strong data-start="925" data-end="955">Alternative – Use a DBMemo</strong>:<br data-start="956" data-end="959" />If you want to view/edit the full content, consider using a <code data-start="1022" data-end="1030">DBMemo</code> component bound to the memo field, triggered by a grid row selection.</p>
</li>
</ol>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Anonymous</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-5859</guid>
                    </item>
				                    <item>
                        <title>RE: Lazarus - How to fix a Database field showing as (memo) in a DBGrid</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-5856</link>
                        <pubDate>Wed, 04 Jun 2025 13:44:31 +0000</pubDate>
                        <description><![CDATA[p.s. if you use a DataModule, then you could consider using this. We will automatically assign the string conversion to any TMemoField in your TDatamodule, so it will save time to assign an ...]]></description>
                        <content:encoded><![CDATA[<p>p.s. if you use a DataModule, then you <em>could</em> consider using this. <br />We will automatically assign the string conversion to any <strong>TMemoField</strong> in your <strong>TDatamodule</strong>, so it will save time to assign an <strong>OnGetText</strong> event for each Field.</p>
<p> </p>
<p>First we need a generic function that can be used on all <strong>TMemoFields</strong> (see explanation above)</p>
<pre contenteditable="false">procedure TDataModule1.SQLQueryGetMemoAsText(Sender: TField; var aText: string; DisplayText: Boolean);
begin
  aText := Sender.AsString;
  DisplayText:=true;
end;     </pre>
<p>Next we assign it at runtime to all <strong>TMemoField</strong> like so (call in the <strong>TDatamodule.OnCreate</strong> event, before opening the database):</p>
<pre contenteditable="false">procedure TDataModule1.SetAllMemoFieldToGetText;
var
  Counter:integer;
begin
  for Counter:=0 to self.ComponentCount-1 do
    if self.Components is TMemoField then
      TMemoField(self.Components).OnGetText:=@self.SQLQueryGetMemoAsText;
end;</pre>
<p> </p>
<p>You'll need to declare both in the <strong>TDatamodule</strong>; and do not forget to call <span style="color: #0000ff"><strong>SetAllMemoFieldToGetText</strong></span> in the <strong>TDatamodule.OnCreate</strong> event!</p>
<pre contenteditable="false">  TDatamodule1 = class(TDataModule)
    ...
    procedure SQLQueryGetMemoAsText(Sender: TField; var aText: string;
      DisplayText: Boolean);
    ...
  public
    ...
    { Set the OnGetText event to spit out plain text instead of (MEMO) }
    procedure SetAllMemoFieldToGetText;
    ...
  end;                                </pre>
<p> </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-how-to-fix-a-database-field-showing-as-memo-in-a-dbgrid/#post-5856</guid>
                    </item>
							        </channel>
        </rss>
		