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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Viewing Results from Function

I have a function that gets the current record# from a Paradox table, but I can't figure out how to 'kick the function off'.  I use this code to asssign the Function's result to a label;

label12.caption := 'Record ' + inttostr(result) + ' of ' + inttostr(table1.recordcount);

;but the function never starts, thus the result is always zero.

The function code is below. How do I get the result?
******************************************************************
 Function RecordNumber(Dataset: TDataset): Longint;
  var
    CursorProps: CurProps;
    RecordProps: RECProps;

  begin
  { Return 0 if dataset is not Paradox or dBASE }
    Result := 0;

    with Dataset do begin
      { Is the dataset active? }
      if State = dsInactive then
        showmessage('datasetclosed');

      Check(DbiGetCursorProps(Handle, CursorProps));
      UpdateCursorPos;

      { Fill RecordProps with the current record's properties }
      Check(DbiGetRecord(Handle, dbiNOLOCK, nil, @RecordProps));

      { What kind of dataset are we looking at? }
      case CursorProps.iSeqNums of
        0: Result := RecordProps.iPhyRecNum;  { dBASE   }
        1: Result := RecordProps.iSeqNum;     { Paradox }
      end; { case }
    end; { with }
  end; { function }
0
d4jaj1
Asked:
d4jaj1
  • 5
  • 4
1 Solution
 
chrbCommented:
It's simple, you call the result wich is only for the current procedure, do this instead :
label12.caption := 'Record ' + inttostr(RecordNumber(You must write a parameter her!)) + ' of ' + inttostr(table1.recordcount);

Hope it helps you :)
Just ask if you dosn't understand

Chr

0
 
d4jaj1Author Commented:
Hate to sound stupid but I'm very new to Delphi.   What parameter are you talking about?  If I put 'Result' there I get an error - "Incompatable types - TDataSet & Integer".  Please Help.
0
 
chrbCommented:
You must send a TDataSet parameter, result is a integer as you see by the error message. Which controlles are you using?

Chr
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
d4jaj1Author Commented:
Now I feel even worse, cause I don't know what you mean by controls.  I hope you mean either what components I'm using or what's in my USES section.  I'm using a Datasource, Table, and db{edit, Combo, Radio group).  My USES section is below.  Thanks you your quick response.

uses

  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Menus, Lines, StdCtrls, ExtCtrls, DB, DBTables, PxConst2, PxEd2, PxDBEd2,
  DBCtrls, Grids, DBGrids, PxValRt2, ComCtrls, Buttons, Mask, fxLoc, dbiprocs,
  dbitypes, dbierrs;
0
 
chrbCommented:
Sorry, I ment component :)
0
 
chrbCommented:
This shuld be the string :

label12.caption := 'Record ' + inttostr(RecordNumber([name of your Datasourcecomponent].dataset)) + ' of ' + inttostr(table1.recordcount);

Hope this should works :)

Chr
0
 
d4jaj1Author Commented:
Nope, Still doesn't work.  I get the error - "Ordnial Type Required".  DSRecipe is my DataSource for the Recipe Table.  Below is the code.  Do you know what this error means?


label12.caption := 'Record ' + inttostr(RecordNumber([DSRecipe].dataset)) + ' of ' + inttostr(tblRecipe.recordcount);
0
 
chrbCommented:
Have you tried DSRecipe.dataset instead of [DSRecipe].dataset? If not try it :) If it dosn't works I will try to see in the help file :)

Now I hope it should works :)

Chr
0
 
d4jaj1Author Commented:
Great job!  I added that code to my dataset onChnage event and it gives me the current and total records.  Thanks.

By the way, I just unlocked another question, called Trapping Function Keys".  The guy who initially answered it never gave me any clarification.  Please answer it if you want.  Its worth fifty points.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now