Different TfrxDBDatasets with the same name

Hi,

how can I specify the dataset for frxReport when more than one dataset with the same name exists?

Sample:
procedure Tfo_demodds.Button2Click(Sender: TObject);
var f1, f2: TForm;
    p1, p2: TfrxPreview;
    ds1, ds2: TMDataSet;
    rep1, rep2: TfrxReport;
begin
  f1 := TForm.Create(nil);
  f1.Name := 'f1';
  p1 := TfrxPreview.Create(f1);
  p1.Parent := f1;
  p1.Align := alClient;
  ds1 := TMDataSet.Create(f1, 'ds', ['1-1', '1-2', '1-3']);
  rep1 := TfrxReport.Create(nil);
  rep1.LoadFromFile('demodds.fr3');
  rep1.Preview := p1;
  f1.Show;
  rep1.PrepareReport();
  f1.SetBounds(10, 10, round(Screen.Width/2)-50, Screen.Height-100);
  //
  f2 := TForm.Create(nil);
  f2.Name := 'f2';
  p2 := TfrxPreview.Create(f2);
  p2.Parent := f2;
  p2.Align := alClient;
  rep2 := TfrxReport.Create(nil);
  // How to force rep2 using ds2 without deleting ds1? Clear and Add does not work.
  ds2 := TMDataSet.Create(f2, 'ds', ['2-1', '2-2', '2-3']);
  rep2.DataSets.Clear;
  rep2.DataSets.Add(ds2);
  rep2.LoadFromFile('demodds.fr3');
  rep2.Preview := p2;
  f2.Show;
  rep2.PrepareReport();
  f2.SetBounds(round(Screen.Width/2), 10, round(Screen.Width/2)-50, Screen.Height-100);
end;

f2 shows the data from ds1. How to force rep2 using ds2 without deleting ds1?

TMDataSet:
  TMDataSet = class (TfrxDBDataset)
  private
    FTable: TkbmMemTable;
    FDataSource: TDataSource;
  public
    constructor Create(AOwner: TComponent; DSName: string; Data: array of string);
  end;

constructor TMDataSet.Create(AOwner: TComponent; DSName: string; Data: array of string);
var sd: string;
begin
  inherited Create(AOwner);
  Name := DSName;
  FTable := TkbmMemTable.Create(Self);
  self.DataSet := FTable;
  FDataSource := TDataSource.Create(self);
  FDataSource.DataSet := FTable;
  FTable.Fielddefs.Add('lfd', ftAutoInc);
  FTable.Fielddefs.Add('field1', ftString, 20);
  FTable.Open;
  for sd in Data do begin
    FTable.Append;
    FTable.FieldByName('field1').Value := sd;
    FTable.Post;
  end;
end;

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.