Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can't use RecNo ... alternatives?

Posted on 1998-07-06
5
Medium Priority
?
354 Views
Last Modified: 2010-04-04
The RecNo function function does not work with my queries (Oracle).

I would like to be able to display to my users a "Record 1 of 9"  message as they scroll through the DBControlGrid.
I can use RecordCount to get the "of 9" part but short of a complicated algorithm (bookmarking, looping thre dataset, etc) to determine record position each time the user adds/deletes/scrolls have not been able to find a replacement for the RecNo function.  

Any suggestions?
0
Comment
Question by:djake021198
5 Comments
 
LVL 1

Expert Comment

by:Greedy
ID: 1357187
Some Oracal Guru will probably know a better way but here are two ways to solve it...once again considering speed it's super important here since your giving back user input this once again implies that it only has to be as fast as a human...

this first way can be used if you can't change the structure of your Oracal table

procedure TForm1.Button1Click(Sender: TObject);
var
  MyCounter: Integer;
  Found: Boolean;
begin
  MyCurrentRecordKey := Table1.FieldByName('YourPrimaryIndexField').AsString;
  Table1.DisableControls;
  Table1.First;
  MyCounter := 1;
  Found := False;
  While (not Table1.EOF) and (not Found) do
  begin
    if MyCurrentRecordKey = Table1.FieldByName('YourPrimaryIndexField').AsString then
      Found := True
    else
    begin
      Table1.Next;
      inc(MyCounter);
    end;
  end;
  Table1.EnableControls;
  Label1.Caption := IntToStr(MyCounter);
end;

Now a better way (faster) to do this would be to add a field called RecordNumber and then just return this in your UpDateLabel routine.  You will also have to make calls to renumber all the records when they do a delete or an insert but that's not too bad just a while loop and a counter... now I keep talking about speed but please note that both of these methods take less than half a second to compleate on my database of about 30,000 records running on a small MSSQL server useing SQL Links so I would bet Oracal shaves another .1 sec off this you can also use TQueries to do this stuff for at least another .2 sec off the times.  Have you looked to see if the Oracal site has any help on this yet?

0
 
LVL 3

Expert Comment

by:KE
ID: 1357188
I don't know much of Oracle servers, but maybee you could make a stored procedure which returns your rows (of course) but also a programatically generated record number. This is just an idea !!!

0
 
LVL 3

Expert Comment

by:vladika
ID: 1357189
There is RowNum statement in the Oracle.
Try use it in your query

select RowNum, ..... from ....


0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1357190
You should ask this question in the Oracle forum, maybe they will tell you the correct sql statement/s.
0
 
LVL 1

Accepted Solution

by:
bozo7 earned 200 total points
ID: 1357191
I got around this by using the following code (example)

function Function1:INteger;
begin
 query1.sql.add('select (count(*)) Count from table1);
 query1.prepare;
 query1.open;
 result := fieldbyname('Count').value;
end;

I ran into the same thing going from Interbase to oracle. This was the best way to do it.
Bozo
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

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…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

824 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