Lazarus: DBGrid shows "(MEMO)" as the value of string fields in SQLite 3

I am trying to write a simple SQLite 3 application using the Lazarus and SQLdb components.

I managed to connect to the database and populate the TDBGrid . The problem is that all columns that are text fields display the value "(MEMO)" rather than a row in the database.

+6
sqlite delphi lazarus memo
source share
7 answers

As the IRC says, you probably need to add the fields of your request to the form (so that โ€œfieldโ€ components are created for them), and then implement the TMemoField.GetText event.

See if an editor for creating components appears in the "fields" field in the object inspector (this is done in Zeos iirc).

0
source share

TDBGrid fields cannot be displayed in the TDBGrid field. Add TDBMemo to the form and connect it to the same TDataSource . In this case, you will see the text in your note.

0
source share

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.

0
source share

I have the same thing in MySQL and Tgrid, so I hope the answer will be the same as it is quite simple :-)

Say if s is the field causing the problem, instead of writing

 SELECT s 

to write

 SELECT LEFT(s,200) AS s 
0
source share

In a rather old forum thread, I found a solution that worked for me (German / English):

SqLite, Zeos und keine Textanzeige, im DbGrid steht (MEMO) - Zeoslib Portal

If you change the field types in the SQLite database from text to varchar , the text is displayed as expected in TDBGrid .

change SQLite columns

As you know, SQLite does not allow changing column field types. So, if you already have valuable data stored in the database, use the steps described in this lesson.

SQLite ALTER TABLE and how to overcome restrictions

Here is another option

  • create a dump ( sqlite3 your.db .dump >your.sql )
  • change the table definitions in the resulting sql (st like s/\<text\>/varchar/ )
  • import into a new database ( sqlite3 your2.db <your.sql )
  • swap names of old and new databases
0
source share

An obvious simple solution is to limit the length of the TEXT in the field using something like VARCHAR (n) in the column type, where n is the maximum number of allowed characters.

0
source share

This article presents the solution: Displaying and editing MEMO fields in Delphi TDBGrid .

Here I summarize what you need to do:

  • in .dfm add OnGetText = MyDataSetMyFieldGetText to TMemoField (here called MyField ) belonging to your dataset (e.g. TTable , here called MyDataSet )
  • in .pas> interface > type > inside your form definition add

     procedure MyDataSetMyFieldGetText(Sender: TField; var Text: string; DisplayText: Boolean); 
  • in .pas> implementation > add this method

     procedure TDM.WorkVisiteNoteGetText(Sender: TField; var Text: string; DisplayText: Boolean); begin Text := Copy(WorkVisiteNote.AsString, 1, 100); end; 
-one
source share

All Articles