Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TDBGrid question

Posted on 1997-03-11
6
Medium Priority
?
422 Views
Last Modified: 2010-04-04
I'm using a TDBGrid in one of my dialogs.  I've set the DataSource and modified the columns in the Column Editor.  My problem is that there is one column that is not part of the database.  I need to dynamically modify the column myself. In other words, I've added a column in the Column Editor and left FieldName blank.  Is there anyway I can get access to the column in the TDBGrid and add the data I need?

Thanks,
Juan C. Miqueli
juan.miqueli@turner.com
0
Comment
Question by:jmiqueli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:pscadden
ID: 1334737
Double-click the dataset component associated with the
datasource to bring up the Fields editor. Go to New and
create a calculated field. This field with the name you give it will
now appear in the TDbgrid. You can use the event for
calculated field to get the information. OR - you can simply
make leave that blank (which I think is what you want) and
the user can enter the field and enter value appropriate
to the other details of the field.
0
 

Author Comment

by:jmiqueli
ID: 1334738
I added the new field and made it a calculated field.  The name came up in the Column Editor.  My only question is, where is the event for calculated fields?  Is it the OnGetData?

Juan
0
 

Expert Comment

by:Singeon
ID: 1334739
The event for calculated fields will be in the Event list for your actual TQuery or TTable dataset component.  Click on the dataset component,  go to its event list, and you will see "OnCalcFields", within which you can set the value of the field.  For example, a field named FIELDNAME in a query component named MyQuery can be set like this:

MyQueryFIELDNAME.Value := ...


Dale

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jmiqueli
ID: 1334740
On the dataset component associated with the datasource, after I entered the new field and made it a Calc field. I went to the event on that field. In the OnGetText of the field there is var parameter passed in called Text. I set the Text field to whatever I needed and that worked. I'm going to try your example.

Thanks for your help,
Juan
0
 

Expert Comment

by:jic
ID: 1334741
Be careful with the OnCalcFields event.  It will fire plenty of times.  Make sure that it is a short procedure
0
 

Accepted Solution

by:
jameshui earned 200 total points
ID: 1334742
Hi!
I want to make things clear first. Are you want to dynamically
modify a column and can rename the field name, right? You want to modify them in the design time or run time?

If you want to modify it on design time, the comment from other user have given a very clear procedure, and I think you can handle it.

If you want to modify it on run time, the main problem is cause by renaming the field's name. Because it will destory the structure of the original database file, so DELPHI will not let user to do so.

Therefore the solution is simple, the only possible way is to create a new table for the database file, so that you can constructe a new structure for it. After created the new table and just copy all the content of the old one.

Creating a new table is quite simple.
(Please take a look on the help file in DELPHI)
(The following code is copied from the DELPHI Help File 'Createtable' item.)

with Table1 do
begin
  Active := False;
  DatabaseName := 'Delphi_Demos';
  TableName := 'CustInfo';
  TableType := ttParadox;
  with FieldDefs do
    begin
    Clear;
    Add('Field1', ftInteger, 0);
    Add('Field2', ftInteger, 0);
    end;
  with IndexDefs do
    begin
    Clear;
    Add('Field1Index', 'Field1', [ixPrimary, ixUnique]);
    end;
CreateTable;
end;

But the creation of a new database is quite slow, if you modify the database's field name frequently, it would become very time wasting.

In order to save time, I suggest that you can use TGrid(Text Grid). You can copy all the data from the database file to TGrid and let user modify them, and you just need to create the new table when user want to save their data.

The TGrid is more easy to handle by programmer if he do need to change the content in the grid oftenly, but the disadvantage is it just can keep the data but can not give the function as database (e.g. SQL, Linking data...).

Help it helps.

James Hui
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question