Solved

how to edit key-field values and avoid immediate resort

Posted on 2000-03-29
8
229 Views
Last Modified: 2010-04-04
I'm using D4 with MS ACCESS 97 tables.
The table is indexed and the value of the indexed field is like a sequence number. Now I have to insert a set of new records into this table (at the position of the cursor in the DBGrid). To do so it is neccesary to edit all records which have a higher sequence number than the sequence number at cursor position, to make space for the new records.
My problem:
When I increase the key-field value of the first record after the cursor position (for example by 4), the changed record wil be resorted acc to the index and the method table.next will not find the second record after the original cursor position.
How can I avoid the resorting of the records until the modifications have been made?
Remark:
I have tried to start the modifications beginning from the bottom, but this works to slow.

does anybody have an idea??
0
Comment
Question by:GePh
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 2668010
Befor you modify the all next records save current position using:

P:= Table1.GetBookMark;


After modifing all records return to that position again using:

Table1.GotoBookmark(P);

P: String;


0
 

Author Comment

by:GePh
ID: 2668072
ok, with bookmark I am able to go back to the original cursor position, but this does not solve my problem to modify all the following records.  
0
 
LVL 7

Expert Comment

by:Motaz
ID: 2668112
If you want to modify the following records write this:

Incerement:= 1;
while not Table1.Eof do
begin
  Table1.Edit;
  Table1.FieldByName('YourField').AsInteger:= Table1.FeildByName('YourField').AsInteger + Increment;
  Table1.Post;
  Table1.Next;
end;
0
Independent Software Vendors: 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:GePh
ID: 2668182
That is what I tried, but this doesn't give the expected result.
Example:
2o records, the value of the key field is 1...20.
Expecting I want to insert 4 records after position 10, I have to increase record 11 to 20 by 4.
Starting with record 11, the new value is 15. Immediately after posting this modification, the former record 11 is now at position 15 and table.next will bring me to record 16 and not to 12, as I want. So I am looking for a method to access the records 11 ... 20 step by step to be able to modify them
0
 
LVL 9

Accepted Solution

by:
ITugay earned 100 total points
ID: 2668254
Let suppose you need to make hole in table between 3 and 4

RCN  DATA
1     aaa
2     bbb
3     ccc
4     ddd
5     eee
6     fff

before inserting record execute SQL expression:
"UPDATE YOUR_TABLE set RCN=RCN+1 WHERE RCN > 3"
then reopen your table and goto to your last inserted record.

All it possible ONLY if RCN is NOT primary key.

Cheers,
Igor




0
 
LVL 7

Expert Comment

by:Motaz
ID: 2668311
You must go from the last record to the current such as:


for i:= 20 downto 11 do
begin
  Table1.Edit;
  Table1.FieldByName('YourField').AsInteger:= i + 4
  Table1.Post;
  Table1.Prior;
end;

This will ensure that the modified records will not moved form it's position.

Motaz
www.geocities.com/motaz1
0
 

Author Comment

by:GePh
ID: 2668500
Your proposal works fine!

Thank you for your help
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2668534
Always wellcome;)
Igor.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 109
DBCtrlGrid, Delphi, Scroll 8 81
firemonkey Android Listview Sort items 7 97
delphi popmenu non latine charcters 3 45
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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