Recent

Author Topic: [SOLVED] Error: Identifier not found?????  (Read 570 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 407
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
[SOLVED] Error: Identifier not found?????
« on: November 20, 2025, 03:33:24 pm »
Looking for advice, maybe someone can see the problem but I can't! I have a small procedure that counts the number of records just as a feedback to the user.  I have this no problem in my Appointments unit but in my ClientsMgt unit, I'm getting this error in the Subject on this topic.  If you can see the issue, please let me know.

In the interface I declare the Query: QryCountClnts: TSQLQuery. Then I declare the procedure UpdateTTLClients in private.  The procedure:

Code: Pascal  [Select][+][-]
  1. procedure TFrmClientsMgt.UpdateTTLClients;
  2. begin
  3.   SafeClose(QryCountClnts);  //=> Ensure a clean state...
  4.   QryCountClnts.SQL.Text:= 'SELECT COUNT(*) AS TTL FROM CLIENTS';
  5.   QryCountClnts.Open;
  6.   try
  7.     EditTTLClients.ReadOnly:= False;
  8.     EditTTLClients.Text:= QryCountClnts.FieldByName('TTL').AsString;
  9.   finally
  10.     EditTTLClients.ReadOnly:= True;
  11.     QryCountClnts.Close;
  12.   end;
  13. end;
  14.  

Then, on the form I have a TEdit called EditTTLClients as per the procedure above.  So, in FormShow I update the TEdit and also when a record is added or deleted I update the TEdit in procedures TFrmClientsMgt.QryClientsAfterDelete and also AfterPost, i.e.

Code: Pascal  [Select][+][-]
  1. procedure TFrmClientsMgt.QryClientsAfterDelete(DataSet: TDataSet);
  2. begin
  3.   UpdateTTLClients;
  4. end;
  5.  
  6. procedure TFrmClientsMgt.QryClientsAfterPost(DataSet: TDataSet);
  7. var
  8.   CurID : Integer;
  9. begin
  10.   UpdateTTLClients;
  11.   //-> Move to the saved record...
  12.   CurID:= DataSet.FieldByName('CUSTNO').AsInteger;
  13.   PMSDataModule.QryClients.Locate('CUSTNO',CurID,[]);
  14. end;
  15.  

When I compile I get these error for every occurrence of QryCountClnts which is just the Query define in Form Create:

Code: Pascal  [Select][+][-]
  1.  //-> Define the properties for the QryCountClnts Query...
  2.   QryCountClnts.DataBase:= PMSDataModule.ConnectPMSDB;
  3.   QryCountClnts.Transaction:= PMSDataModule.TransPMSDB;
  4.   QryCountClnts.SQL.Text:= 'SELECT COUNT(*) AS TTL FROM CLIENTS';
  5.  

Can't figure this one out, any advice I will probably kick myself, probably very obvious...
« Last Edit: December 04, 2025, 09:30:25 pm by 1HuntnMan »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12562
  • FPC developer.
Re: Error: Identifier not found?????
« Reply #1 on: November 20, 2025, 03:38:26 pm »
QueryCOUNTClnts vs QryClients ?

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 407
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Error: Identifier not found?????
« Reply #2 on: November 20, 2025, 05:58:53 pm »
QryClients is on the DataModule. This QueryCOUNTClnts is on the form, local.  It's separate and only used AfterPost/AfterDelete.  The problem is declaring it, which this is exactly the way I have this setup in the Appointments unit/form and it works.  This is a Identifier not found: QryCountClnts.  It's got to be the way I'm declaring it, in the interface.

rvk

  • Hero Member
  • *****
  • Posts: 6890
Re: Error: Identifier not found?????
« Reply #3 on: November 21, 2025, 10:24:52 am »
QryClients is on the DataModule. This QueryCOUNTClnts is on the form, local.  It's separate and only used AfterPost/AfterDelete.  The problem is declaring it, which this is exactly the way I have this setup in the Appointments unit/form and it works.  This is a Identifier not found: QryCountClnts.  It's got to be the way I'm declaring it, in the interface.
Then at least show how you declared it (where).

You say the QueryCOUNTClnts is on the form... then you don't add this yourself? So it's just in TFrmClientsMgt.
So you should be able to use QryCountClnts in all class functions and procedures of TFrmClientsMgt.

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 407
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Error: Identifier not found?????
« Reply #4 on: November 30, 2025, 09:11:55 pm »
rvk, I rather rebuilt the form and if I don't add this particular Query, it runs fine.  I added quite awhile back just for info. for the user, i.e. how many contacts, clients or appointments. The Connection and Transaction components are on the DataModule.  I did some changing and did have everything queries, datasources, the connection/trans on the datamodule.  I'm revamping the whole app and currently have just the mainform, datamodule and one app. form - Appointments.  The only query components I have on the datamodule is the Connection, Trans and the queries/datasources for lookup tables, i.e. States, Countries, etc.  DropDownCombo's on the forms, i.e. Appointments. Only 2 drop-downs, using JvDBLookUp component because I can drop-down more than one lookup field, State Abbrev. and the State Fullname. On the one form Appointments, have 3 queries with their datasources: Appts., Client and Contacts tables/queries.  Redesigned the form and compiled and had a few errors from typos but then only error which doesn't make sense is this same query for displaying in a TEdit the number of appointments.  See attached.  Also, it's just a Query component, no datasource, here's the code/procedure with where it's declared first as Private and then a snipped in the Form Create and then the Update Procedure which is used AfterDelete and AfterPost to show in a TEdit:

Code: Pascal  [Select][+][-]
  1.   private
  2.     Searchfield : String;
  3.     Keys        : TStringList;
  4.     procedure QryAppmtsAfterDelete(DataSet: TDataSet);
  5.     procedure QryAppmtsAfterPost(DataSet: TDataSet);
  6.     procedure UpdateTTLAppmts;
  7.  
  8. procedure TFrmAppmnts.FormCreate(Sender: TObject);
  9. begin
  10.   Keys:= TStringList.Create;
  11.   //=> Add Items to the CmboBxIndex...
  12.   CmboBxIndex.Items.Clear;
  13.   CmboBxIndex.Items.Add('Client/Customer');
  14.   CmboBxIndex.Items.Add('Contacts (L,F,M');
  15.   CmboBxIndex.Items.Add('Appt. Date');
  16.   CmboBxIndex.Items.Add('Appt. No.');
  17.   //=> Define the properties for the QryCountAppmts query...
  18.   QryCountAppmts.DataBase:= PMSDataModule.ConnectPMSDB_RO;
  19.   QryCountAppmts.Transaction:= PMSDataModule.TransRO;
  20.   QryCountAppmts.SQL.Text:= 'SELECT COUNT(*) AS TTL FROM APPOINTMENTS';
  21.  
  22. procedure TFrmAppmnts.UpdateTTLAppmts;
  23. begin
  24.   QryCountAppmts.SQL.Text:= 'SELECT COUNT(*) AS TTL FROM APPOINTMENTS';
  25.   QryCountAppmts.Open;
  26.   try
  27.     EditTTLAppts.ReadOnly:= False;
  28.     EditTTLAppts.Text:= QryCountAppmts.FieldByName('TTL').AsString;
  29.   finally
  30.     EditTTLAppts.ReadOnly:= True;
  31.     QryCountAppmts.Close;
  32.     EditTTLAppts.Refresh;
  33.   end;
  34. end;
  35.  
  36. procedure TFrmAppmnts.QryAppmtsAfterDelete(DataSet: TDataSet);
  37. begin
  38.   UpdateTTLAppmts;
  39. end;
  40.  
  41. procedure TFrmAppmnts.QryAppmtsAfterPost(DataSet: TDataSet);
  42. var
  43.   CurID : Integer;
  44. begin
  45.   UpdateTTLAppmts;
  46.   //=> Move to the saved record...
  47.   CurID:= DataSet.FieldByName('APPTID').AsInteger;
  48.   QryAppmts.Locate('APPTID',CurID,[]);
  49.   DBChkBxActive.Refresh; //=> Check to verify DBChkBxActive refreshes...
  50. end;
  51.  

The error is occuring at the line above in FormCreate, not during compile, compile has no errors, it's happening only at runtime the instant the form is created in the FormCreate at the line above or here it is:
QryCountAppmts.DataBase:= PMSDataModule.ConnectPMSDB_RO;

Error attached...


rvk

  • Hero Member
  • *****
  • Posts: 6890
Re: Error: Identifier not found?????
« Reply #5 on: November 30, 2025, 09:30:48 pm »
The error is occuring at the line above in FormCreate, not during compile, compile has no errors, it's happening only at runtime the instant the form is created in the FormCreate at the line above or here it is:
QryCountAppmts.DataBase:= PMSDataModule.ConnectPMSDB_RO;

Error attached...
That just looks like your form is created before your data module.
Check the order in which your forms/modules are created.
Your data module should be the first one (because you depend on it during the form create).

If the order is correct, then when and how is PMSDataModule.ConnectPMSDB_RO created?
But my guess PMSDataModule is not yet created (which works result in access violation).
« Last Edit: November 30, 2025, 09:34:06 pm by rvk »

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 407
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Error: Identifier not found?????
« Reply #6 on: December 01, 2025, 06:03:05 pm »
Yup, forgot to check the lpr unit. I hand coded it in with the DataModule created first before the Main unit and then created the datamodule, mainform, and the Appointments form. Compiled and cleaned up and when I created the datamodule Lazarus put the Create statement for the datamodule into the lpr unit again and it was declared twice.  That fixed it, thanks for advising about the create order in the LPR.
Take care...

 

TinyPortal © 2005-2018