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();
begin
  dbgList.DataSource := dmProgramDatabase.dsrCaches;
end;

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.