Solved

TDBGrid question

Posted on 1997-03-11
6
419 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 100 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

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!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses
Course of the Month4 days, 4 hours left to enroll

630 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