Check if an adoquery field exists

edited 8:53AM in FastReport 4.0
Hello, I made an adoquery in access whose fields change each time I call it from fast report. How can I check if it's fields exist when I use it in fast report. I used this code
if <ADOQuery2.fieldbyname('aircrewstatus') = null then showmessage('don't exist');
but it does not work and this message appears ( Can't find field "aircrewstatus"). Can anyone help me?? Thanks.

Comments

  • Anu de DeusAnu de Deus Hampshire, UK
    edited January 2011
    try using the ADOQuery2.GetFieldNames procedure and analise the results.

    They are part of TDataset and implemented in the frx editor, should be fine, take a look at the Classes tab in the right side of the frx editor, plenty of good stuff there.
  • edited 8:53AM
    try using the ADOQuery2.GetFieldNames procedure and analise the results.

    They are part of TDataset and implemented in the frx editor, should be fine, take a look at the Classes tab in the right side of the frx editor, plenty of good stuff there.
  • edited 8:53AM
    I tried that showmessage(adoquery2.GetFieldNames); but didn't work. The message Undeclared Idendifier : 'GetFieldNames' appeared. Am I doing something wrong?
  • Anu de DeusAnu de Deus Hampshire, UK
    edited 8:53AM
    yes, you are.
    As I said, look at the tab, there is the function declaration there, with its required parameters
  • edited 8:53AM
    Sorry but I can't find the solution. I found the procedure GetFieldNames(List: TStrings) but I don't know how to use it. What should I write in the parenthesis? Can you send me an example? Thanks.
  • gpigpi
    edited 8:53AM
    var List: TStringList;           
    begin
         ADOQuery1.Open;              
         List := TStringList.Create;                                                                                 
         ADOQuery1.GetFieldList(List);
         if List.IndexOf('Company') <> -1 then ShowMessage('Company field exists');
         List.Free;                           
    end.
    
  • edited 8:53AM
    It works!!! Thank you very much.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.