I am trying to use FDQuery
at run-time only. I've done a lot of research and tried several changes, but all of them ends with Access Violetion
, so I suspect that the component is not instantiating correctly. I looked for examples on the internet to study and understand my mistake, and until that moment I did not find anything I did not do.
I leave here my example of how the code is now, and please ask someone to 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;