0

I have created a Form with 4 DBExpress elements. Until the db elements was in the form everything worked fine. The problem born when I created a DataModule to have it more tidy. I already did 'use unit' and selected the DataModule but when I run the application it give me errors when I attempt to use the db elements.

All I do is to click from the Form to a button having this code:

procedure TForm1.Button1Click(Sender: TObject);
begin

SQLQuery1.Close;
SQLQuery1.SQL.Clear;
SQLQuery1.sql.add('select * from help');
SQLQuery1.ExecSQL; 

end; 
                   

Every line containing SQLQuery1 (element inside the DataModule) has an error. How do I make the DataModule elements recognized by the Form?

Wario
  • 13
  • 6

1 Answers1

1

You need to qualify the DB components with the name of the DataModule they belong to, eg:

uses
  ..., MyDataModule;

procedure TForm1.Button1Click(Sender: TObject);
begin
  DataModule1.SQLQuery1.Close;
  DataModule1.SQLQuery1.SQL.Clear;
  DataModule1.SQLQuery1.sql.add('select * from help');
  DataModule1.SQLQuery1.ExecSQL;
end;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Wario
  • 13
  • 6
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 22 '21 at 10:02
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 22 '21 at 19:10