I'm on this very simple piece of code but I couldn't do it work properly. I dropped into form a LibraryLoader and set the absolute path to .dll, a SQLite3Connection and set the absolute path to database, a SQLQuery, a DataSource (that points to the SQLQuery) and a DBGrid linked to that DataSource. In SQL Property of SQLQuery I have the following statement:
SELECT nome AS "NOME",
strftime("%d/%m/%Y", DATE(dt_apfd)) AS "APFD",
strftime("%d/%m/%Y", DATE(dt_prev)) AS "PREV",
numero AS "PROCESSO"
FROM presos INNER JOIN processos
ON processos.idproc = presos.idproc;
For load results into DBGrid I'm using the code:
procedure TForm1.Button1Click(Sender: TObject);
begin
SQLite3Connection1.Open;
DBGrid1.Columns.Clear;
SQLQuery1.Active:=True;
//SQLQuery1.FieldDefs[0].DataType:=TFieldType.ftString;
DBGrid1.Columns.Add;
DBGrid1.Columns[0].FieldName:=SQLQuery1.FieldDefs[0].Name;
DBGrid1.Columns.Add;
DBGrid1.Columns[1].FieldName:=SQLQuery1.FieldDefs[1].Name;
DBGrid1.Columns.Add;
DBGrid1.Columns[2].FieldName:=SQLQuery1.FieldDefs[2].Name;
DBGrid1.Columns.Add;
DBGrid1.Columns[3].FieldName:=SQLQuery1.FieldDefs[3].Name;
end;
The Problem: when I activete SQLQuery, DBGrid is showing (MEMO) on filds "NOME" and "PROCESSO" instead the actually string. As you can see, I tried to ``SQLQuery1.FieldDefs[0].DataType:=TFieldType.ftString;``, but it mades no difference.
I tried to change it via Properties, but actually, catch fields and its properties by activating the query has a bug wich crashes Lazarus to death, so I was trying to do it writting in program.