Hi I am trying to insert records into a small Dbase file. Whenever I insert it always appends.

If I do db.prior; db.prior; (which should be at least 2 records from the end) and do a db.insert, it always appends.
I do not want to use an index as the record has to be put in the position where the cursor is.

If I try a table and point to a record and activate db.insert, it still appends.

What am I doing wrong ?

Thanks Wallace

when you're doing an insert operation, all the time the record inserted is the last. i suggest you to use an index

best regards.

when you're doing an insert operation, all the time the record inserted is the last. i suggest you to use an index

best regards.

I need to insert at the record pointer. The program is a machine operation table and operations need to be added to the list where ever the operator needs them. If I add an index, I will have to renumber all the operatins after the current insert position to keep the order. The Delphi says that Insert, inserts at the current record pointer, but, I can't get it to work.

Thanks Wallace

I assume you are using a TTable or TQuery to handle your dBASE file. In both cases, those classes are descendents of TDataSet. The Delphi Help system states the following concering the Insert and InsertRecord methods:
For dBASE, FoxPro, and Access tables, the record is physically appended to the dataset at the end. If an index happens to be active, the new record may appear in a position relative to the index, but the record is still actually stored at the end of the table.
Sorry, but you need to use an index and do a little programming to keep the index current.

Thanks Will do index. Means I can also move operations up and down on list. Cheers Wallace

What you're doing wrong is using the record position as anything of value...strictly old school (dBase is one of the few database programs that supports it and, yes, I go back to dbase II) and it will get you into trouble. Imagine you delete a record and pack....OHMIGOD!
So....what you WANT to do is come up with a unique key. Number? Set of letters? dBase likes character strings better than integers/numbers, but if you switch to a different database in the future then you are more likely to encounter Integers as keys.
If it is vital that you have things in order, then drop back to the old BASIC technique of adding records separated by 10 or 100 so that you can "insert" records. If this is something you need to do all of the time, then you'd best give out your reasoning for wanting the records in a specific order.
And if you absolutely MUST avoid an index, you can always add then sort by the field to a new table, etc. etc.
Nothing personal, but why dBase? Lots of better choices.
Doug


If I try a table and point to a record and activate db.insert, it still appends.

What am I doing wrong ?

Thanks Wallace

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.