Wizard won’t allow creating TQuery grid with only a few visible fields

Wizard won’t allow creating TQuery grid with only a few visible fields

Question:
I am developing a database/intranet package for which I need to use a grid based on a TQuery, but I only need a few of the fields to show up in the grid. The wizard won’t let me do it? What am I missing/overlooking?

Answer:
This is a stumbling block for a lot of people. And it’s not reallydue to missing something, it’s just due to unfamiliarity with the way thedata-aware components work. Think of the way data is displayed in Delphi asa layer cake:

Layer 4Data-aware Component
Layer 3DataSource
Layer 2Field-link (TField)
Layer 1DataSet

The top layer is the component that displays the data; in your case, theTDBGrid. It’s connected to a DataSource component, which in turn is connectto TDataLinks or TFields. These are then connected to the underlying dataset.

You might think that the “visibility” of data is controlled by the DBGrid.Actually, data visibility is controlled at a much lower level, the TField level/Data-link level. I won’t go into TDataLink,because that’s a bit more on the esoteric side of things, but I will saythis: If you don’t use TField definitions for your dataset, Delphi willdefault to use the data links, which means that all your columns will bedisplayed. This is probably the behavior you’re seeing right now.

However, if you define TFields for your dataset component, only the onesyou add will be displayed in your grid or, if you’ve added all fieldsfrom the dataset to have TField definitions, only those fields that havetheir Visible property set to True will have their data displayed.

But how do you do define TFields for a dataset in the first place?

Well, I’m assuming that you have a TDBGrid, a TDataSource and a TQuery dropped onto your form. I’m further assuming that you’ve set up your query.To get at the TFields, all you have to do is double-click on the TQuerycomponent. This will bring up the Fields Editor. When you do this, it’ll beblank, but don’t worry. Press Ctrl-A to add fields, and an “Add Fields”dialog box will pop up, containing a list of available fields that can haveTField definitions attached to them. By default, all of the fields areselected. Press OK if you want all of them, or select only the fields youwant to display.

Once you’ve selected your fields, you’ll see them listed inthe fields editor. Click on one of the fields. Look in the ObjectInspector. You’ll see a bunch of properties associated with the field. Inparticular, look at the Visible property. By default, it will be set totrue. If you don’t want the data to be displayed, set the propertyto false.

That’s it in a nutshell. Refer to the online help for amore detailed explanation. Also, the Database Application Developer’s Guidethat came with your Delphi manual set will provide you with more robustinformation than I’ve given here.

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as