How To…Search Available Dataviews

Question

“How do I search the available dataviews created in DADE for a specific one?”

Solution

Use the TppDataView.Description property to find the name of each dataview and locate the one you need.  Start by accessing the datamodule using the daGetDataModule routine.  Next loop through each dataview in the TppDataModule.DataViews list to find the desired dataview.

Download: SearchDataviewsByName.zip

Sample Delphi code:

procedure TForm1.ppReport1BeforePrint(Sender: TObject);
var
  lDataModule: TdaDataModule;
  liIndex: Integer;
  lDataView: TdaQueryDataview;
  lDataPipeline: TppDBPipeline;
  lSQL: TdaSQL;
  lsPipelineName: String;
begin

  {get the datamodule}
  lDataModule := daGetDataModule(ppReport1);

  lsPipelineName := '';

  if (lDataModule <> nil) then
    begin

      for liIndex := 0 to lDataModule.DataViewCount - 1 do
        begin
          lDataView := TdaQueryDataView(lDataModule.DataViews[liIndex]);

          if (lDataView <> nil) and (lDataView is TdaQueryDataView) then
            begin
              {only custom dataviews can have multiple data pipelines}
              lDataPipeline := TppDBPipeline(lDataView.DataPipelines[0]);

              if (lDataPipeline = ppReport1.DataPipeline) then
                begin
                  ShowMessage(lDataView.Description);

                  lsPipelineName := lDataView.Description;

                  {do something with SQL object}
                  lSQL := lDataview.SQL;
                end;
            end;

        end;

    end;

end;