Solved

TDBGrid question

Posted on 1997-03-11
6
410 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 174
loading dll from external path 1 212
FMX StringGrid1->Canvas->FillRect Problem 3 129
Comparing dates in Delphi. Greater than/ Less than 3 119
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now