Accessing the dataset's properties

edited January 2010 in FastReport 4.0
How can I access the Properties of a report's dataset ?

It's a TClientDataset (so SQL isn't available) and I want to set its Filter and IndexFieldName properties. If I code :

<Customers>.IndexFieldName := 'Country';

I get : "; expected"

I assume that the place to do this is in Page1OnBeforePrint ?

I want to produce a record count by, say, the Country field. I have

Group header : Country
Master band
Group footer : ([COUNT(MasterData1,1)]

But no counts appear. What am I doing wrong ?

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 6:20PM
    set your masterdataband dataset property to your frxdbdataset that is connected to your tclientdataset, make sure your tclientdataset is sorted in the order you want.

    your report will group itself into the correct groups.
    Group footer : [COUNT(MasterData1,1)]

    typical way to hide would be to set visible property in obp event of mdband.
    some other notes when passing string values you need extra delimiters.
    wrong event use on start report event.
    read the programmers manual as working from delphi.
    the users manual as from within the report except for exporting.
    compile and run the main demos for ideas on reports and concepts
    and look at the data unit to see how frxdbdatasets are connected.
  • edited January 2010
    Thanks. Groups now works.

    But you didn't answer (or I didn't understand) :

    How can I access the Properties of a report's dataset ?

    It's a TClientDataset (so SQL isn't available) and I want to set its IndexFieldName property.
  • gordkgordk St.Catherines On. Canada.
    edited 6:20PM
    your tclientdataset is located outside of the report so access it from delphi prior to calling
    showreport or prepare report.
  • edited 6:20PM
    <your tclientdataset is located outside of the report >

    So isn't there any way of allowing the report's user to decide the sort order of the records ?
  • gordkgordk St.Catherines On. Canada.
    edited 6:20PM
    internally only if you are using components of one of the fr supplied dbengines or 3rd party
    dbengines
    if you are using external objects then you can create your own outside dialogforms
    to perform those settings.
  • edited 6:20PM
    < internally only if you are using components of one of the fr supplied dbengines >

    I'm using fr "out-of-the box". I assume that it's using midas to support TClientDataset.

    So how do I access it please ?
  • gordkgordk St.Catherines On. Canada.
    edited 6:20PM
    out of the box means nothing (one needs to know which box).

    what version build and level of fr are you using. i'm thinking you might be in the wrong forum
  • edited 6:20PM
    < out of the box means nothing (one needs to know which box) >

    It means - as downloaded without any re-configuration.

    < what version build and level of fr are you using >

    4.9.2

    Demo version (until I'm satisfied that it has the features that I need)
  • gordkgordk St.Catherines On. Canada.
    edited 6:20PM
    we seem to be misunderstanding each other.
    are you trying to build client/server apps as per the c/s demos?
  • edited 6:20PM
    < are you trying to build client/server apps as per the c/s demos? >

    No, it's a local TClientDataset loaded from a file then handled in memory by midas.dll.
  • gordkgordk St.Catherines On. Canada.
    edited 6:20PM
    IanT wrote: »
    < are you trying to build client/server apps as per the c/s demos? >

    No, it's a local TClientDataset loaded from a file then handled in memory by midas.dll.
    so you connected the tfrxdbdataset to the memtable or the tclientdataset?
  • edited 6:20PM
    < so you connected the tfrxdbdataset to the memtable or the tclientdataset? >

    Yes, to the tclientdataset
  • gordkgordk St.Catherines On. Canada.
    edited 6:20PM
    i think what you are not understanding is that a tfrxdbdataset is an external(to the report)
    connection to data
    it opens closes and moves through the data it is connected to and retreives field names.
    it does not handle setting of properties of the (table,querie,tdataset) to which it is connected, from inside the report. it must be done externally.
    the analogy is the same as table/query/clientdataset > tdatasource > grid.
    here is a sample.
    //top of code page
    var
    i: Integer;
    ds: TfrxDataSet;
    list: TStringList;
    // begin end. block at bottom
    ds := Report.GetDataset('frxDBDataSet1');
    list := TStringList.Create;
    ds.GetFieldList(list);

    for i := 0 to list.Count - 1 do
    somevar := ds.Value[list]; // get field value by its name
  • edited 6:20PM
    <I think what you are not understanding is that a tfrxdbdataset is an external(to the report) >

    I do understand

    < it does not handle setting of properties of the (table,querie,tdataset) to which it is connected, from inside the report >

    But that's the workaround that I'm trying to achieve. Or rather, I want the report to set the sorting order of the records without using SQL.

    Ideally : frxDBDatabase1.Dataset.IndexFieldNames := [as specified]

    But if that isn't possible (which would be a useful improvement), is there some way of communicating back to the calling program with, say, a TMessage passing the name(s) of the index fields and the ascending/descending order. If that triggers an event in the main app, it could respond by changing the index field before the report is prepared.
  • gordkgordk St.Catherines On. Canada.
    edited 6:20PM
    you create your own functions to pass out the values to delphi.
    here is another you might try this reads props but you might be albe to set as well.

    delphi form code
    procedure TForm1.Button4Click(Sender: TObject);
    begin
    frxreport3.Clear;
    frxreport3.OnBeforePrint := nil;// disconnect unwanted events
    frxreport3.OnAfterPrint := nil;
    frxreport3.LoadFromFile(wpath+'vartest4.fr3');
    frxReport3.Variables.Clear;//clear list
    frxreport3.script.AddForm(self);// add the current delphi form

    if cb1.checked then
    frxreport3.designreport else frxreport3.showreport;
    end;


    report code
    var
    mpath:string;
    begin
    mpath := form1.label1.caption;

    end.
  • edited 6:20PM
    < you create your own functions to pass out the values to delphi. >

    I can't get this to work.

    If I buy the source code version of fr, will I be able to patch the code so that I can sort the data ?
  • edited 6:20PM
    IanT wrote: »
    < you create your own functions to pass out the values to delphi. >

    I can't get this to work.

    If I buy the source code version of fr, will I be able to patch the code so that I can sort the data ?

    This should not be difficult. I had followed the manual and define many custom functions for communication between FR reports and my own Delphi applications, including setting fieldindexes and filters in ClientDataSet.

    Also, I see that TClientDataSet is included in the Report Classes so maybe after you add the form (or the datamodule that contain your CDS), you can directly control your CDS in FR script. I didnt test this b4 though.
  • edited 6:20PM
    A way to order data from an external Dataset (like IanT suggested: frxDBDatabase1.Dataset.IndexFieldNames := [as specified]) would be EXTREMELY helpful. My example is that I have one dataset to be used in 2 different reports. The reports take the same data but order/groups it differently.

    I really don't like doing this from Delphi because, if I change the order of the dataset, only one of the two reports would run correctly. I'd have to change it before each of them, and that means the correctness of the report relies on a additional line of code (ordering the dataset) executing first.

    Crystal Reports has functionality to order the result data, that's what we need here.

    Just my thoughts.

  • btwariesbtwaries philippines
    edited 6:20PM
    It opens and closes and moves through the data on which it is connected and retreive the name field.
  • Anu de DeusAnu de Deus Hampshire, UK
    edited June 2010
    It's possible, but not in 1 or 2 lines as you would like to have.
    What you need is to put code in the OnPage1BeforePrint script to do the hard work.
    First, in your designer, I suggest you use the MemoView.tag property of every field to be displayed and put the order on it, starting from 1. So instead of having a 'order' property like you wanted, you use the .tag to do the job.

    Then read the order of fields that you want from some sort of data source, or variable. A stringlist with the fieldnames in each line would do the job.
    Then:

    for each element in your stringlist
    Find the control in the page with the .tag corresponding to the element index in the stringlist, set its Text property to '[fieldname]', where fieldname is the value read from the stringlist.

    So, for each different report with different fields or orders, all you have to change is the stringlist contents.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.