Accessing the dataset's properties
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 ?
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
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.
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.
showreport or prepare report.
So isn't there any way of allowing the report's user to decide the sort order of the records ?
dbengines
if you are using external objects then you can create your own outside dialogforms
to perform those settings.
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 ?
what version build and level of fr are you using. i'm thinking you might be in the wrong forum
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)
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.
Yes, to the tclientdataset
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
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.
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.
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.
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.
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.