1
I’m trying to use the FDQuery
only at runtime. I’ve done a lot of research and tried several changes, but they all end with Access Violetion
, so it’s suspicious that the component isn’t being instantiated properly. I looked for examples on the Internet to study and understand my mistake, and until now I found nothing I haven’t done.
I leave here my example of how the code is now, and please someone point out where it is wrong.
private
{ Private declarations }
public
{ Public declarations }
FDInsertForn : TFDQuery;
end;
implementation
procedure TFLancamento.EdRazaoExit(Sender: TObject);
const
SQLInsert : String = 'INSERT INTO FOR1A' + sLineBreak +
'( CNPJ,FANTASIA,RAZAO)VALUES' + sLineBreak +
'( :CN, :FANTASIA, :RAZAO)';
begin
FDInsertForn.Connection:= UDM.FDConexao;
FDInsertForn.SQL.Clear;
FDInsertForn.SQL.Add(SQLInsert);
FDInsertForn.Params.ParamByName('CN').AsString:= dado;
FDInsertForn.Params.ParamByName('FANTASIA').AsString:= EdFantasia.Text;
FDInsertForn.Params.ParamByName('RAZAO').AsString:= EdRazao.Text;
FDInsertForn.ExecSQL;
end;
In which line does the error? What is the error?
– Roberto de Campos
Error from the first line. I got to comment on
Params
and do a Debug with Break Point but as soon as the first line starts comes access violetion.– Danilo Araujo
So probably your
FDQuery
not created, try adding this lineFDInsertForn := TFDQuery.Create(nil);
beforeFDInsertForn.Connection:= UDM.FDConexao;
– Roberto de Campos
The problem was solved, I looked for this example you gave me and even in the official documentation of Embarcadeiro has this quote
– Danilo Araujo
I added the answer, with a few more details as well.
– Roberto de Campos