Solved

how to edit key-field values and avoid immediate resort

Posted on 2000-03-29
8
228 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
  • 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Send message from delphi to whatsapp, is it possible? 3 1,699
code issue 8 156
LAN or WAN ? 11 96
update joined tables 2 55
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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