I am trying to create a form dynamicly and thus I need to initialize my DBGrid with code.

{ Connect the DBGrid to the database. }
procedure TfrmRemoveRecord.InitDBGrid();
  dbgList.DataSource := dmProgramDatabase.dsrCaches;

But I get an access violation error.

What is dmProgramDatabase? My guess is that it is a data module and you have not created it before InitDBGrid is called.

Solved the issue. I needed to call the initialization in the OnActivate and not in the OnCreate of the form.