if you are really sure you will use this event then you can even forget about the if .. then part, and just cast your dataset in TTable
Main Topics
Browse All TopicsThis must be a really stoopid question, but in TClientDataSet events, such as BeforeInsert, there seems to be no way to assign any of the Index properties within the event code. The variable that gets passed into the Event is DataSet: TDataSet, but it is not possible to do, say:-
dataset.indexfieldnames:='
Can someone enlighten me as to how to do this within the event coding - I am fed up of having to do this in the coding leading up to the Insertion. Or maybe there's a better way to do it...
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
from Delphi Help (translated from french)
IndexFieldNames is an alternate mean to specify the index to use in a table. ... The properties IndexName and IndexFieldNames are mutually exclusive. Affecting one value erases the other.
Main difference is that IndexFieldNames can set more than one index field. If only one index field is needed, moorhouselondon could use TTable(DataSet).IndexName:
same problem, same solution, and I don't think that using IndexFieldNames with only one field is much less efficient than IndexName
Progress Report
Thanks folks, great to have such prompt help when it's needed first thing in the morning UK time.
I tried epasquier's suggestion and it didn't work because my ClientDataSet is not a TTable. However, I then tried:-
Tclientdataset(DataSet).in
which did work, just testing that as I type, I pasted it into the wrong routine inititially which caused a bit of head-scratching, hence the delay in me getting back to you.
Geert_Gruwez: It is the Auto-inc field that I'm after (I'm using mysql), but I seemed to have a lot of bother getting that to work for some reason, so thought I'd do it manually through BeforeInsert/AfterInsert. That works really well for me, but occasionally I forget to set the Index to Id before doing an Insert, hence my Question here today.
I'm just waiting for my test utility to finish, then I'll report back...
Business Accounts
Answer for Membership
by: epasquierPosted on 2009-10-30 at 01:25:23ID: 25700927
indexfieldnames is not a property of TDataSet but of TTable.
names:='bl ah';
So you should write :
if DataSet Is TTable then TTable(DataSet).indexfield