1 (edited by prahousefamily 2018-09-06 08:05:00)

Topic: Example Create Unlimited Tdataset For Design Report By One Script

I will little help MVD Community  create multiple tdataset in report design by use value string in Tmemo custom syntax

Syntax
<dataset name"xxx">sql</dataset>

Example Image
https://image.ibb.co/kvBmSz/2018_09_06_001.png

Example Image With Design & Preview
https://image.ibb.co/cX6s0K/2018_09_06_003.png
https://image.ibb.co/kd1QLK/2018_09_06_004.png

Open Code

//Fix 2018-09-06 Script Example Report Flag
            
procedure Form1_Button3_OnClick (Sender: TObject; var Cancel: boolean);
var         
frxDBDatasets : array[0..999] OF TfrxDBDataset;
dts : array[0..999] OF Tdataset;
i : integer ;
dtssql : string;
dtsname : String;
begin
    Form1.frxReport.Clear;
    Form1.frxReport.DataSets.Clear;
    For i := 0 To Form1.ComboBox1.Items.Count - 1 Do
    begin
        //test show message
        dtsname := (
        Copy(
        Form1.ComboBox1.Items[i],
        Pos('<dataset name"',Form1.ComboBox1.Items[i])+14,
        Pos('">',Form1.ComboBox1.Items[i])-(Pos('<dataset name"',Form1.ComboBox1.Items[i])+14),
        )
        );
        Showmessage(dtsname);
        dtssql :=
        Copy(
        Form1.ComboBox1.Items[i],
        (Pos('">',Form1.ComboBox1.Items[i])+2),
        Pos('</dataset>',Form1.ComboBox1.Items[i]) - (Pos('">',Form1.ComboBox1.Items[i])+2)
        ) ;
        SQLQuery(dtssql, dts[i]);
        frxDBDatasets[i] := TfrxDBDataset.Create(Form1);
        frxDBDatasets[i].UserName        := dtsname;
        frxDBDatasets[i].CloseDataSource := True;
        frxDBDatasets[i].OpenDataSource  := True;
        frxDBDatasets[i].DataSet         := dts[i];
        Form1.frxReport.DataSets.Add(frxDBDatasets[i]);
    end;
    For i := 0 To Form1.ComboBox1.Items.Count - 1 Do
    frxDBDatasets[i].DataSet.Close ;

    Form1.frxReport.LoadFromFile(ExtractFilePath(Application.ExeName)+'Report\test.fr3');
    Form1.frxReport.ShowReport;

    For i := 0 To Form1.ComboBox1.Items.Count - 1 Do
    frxDBDatasets[i].DataSet.Free ;

end;

procedure Form1_Button2_OnClick (Sender: TObject; var Cancel: boolean);
var
st_temp : String;
vt_name : tstringlist;
result_sql : String;
get_x,get_y : Integer;
para_x,para_y : Integer;
paraname : string;
dts : array[0..999] of ttoolbar;
dtsi: integer;
begin
//start
    st_temp := Form1.Memo1.Text ;
    result_sql := Form1.Memo1.Text;
    vt_name := tstringlist.Create ;
    vt_name.Clear ;
    Form1.ComboBox1.Items.clear ;
    Repeat
    begin
        get_x    := Pos('<dataset name"',st_temp);
        st_temp  := Copy(st_temp,get_x,Length(st_temp));
        get_y    := Pos('</dataset>',st_temp) ;
        paraname := Copy(st_temp,1,get_y+9);
        IF Pos(paraname,vt_name.Text) <= 0 Then
        vt_name.Add(paraname) ;
        Form1.ComboBox1.Items.add(paraname);
        st_temp  := copy(st_temp,get_y+10,Length(st_temp) );
    end;
    until Pos('<dataset name"',st_temp) <= 0;
end;

procedure Form1_Button1_OnClick (Sender: TObject; var Cancel: boolean);
var
frxDBDatasets : array[0..999] OF TfrxDBDataset;
dts : array[0..999] OF Tdataset;
i : integer ;
dtssql : string;
dtsname : String;
begin
    Form1.frxReport.Clear;
    Form1.frxReport.DataSets.Clear;
    For i := 0 To Form1.ComboBox1.Items.Count - 1 Do
    begin
        //test show message
        dtsname := (
        Copy(
        Form1.ComboBox1.Items[i],
        Pos('<dataset name"',Form1.ComboBox1.Items[i])+14,
        Pos('">',Form1.ComboBox1.Items[i])-(Pos('<dataset name"',Form1.ComboBox1.Items[i])+14),
        )
        );
        Showmessage(dtsname);
        dtssql :=
        Copy(
        Form1.ComboBox1.Items[i],
        (Pos('">',Form1.ComboBox1.Items[i])+2),
        Pos('</dataset>',Form1.ComboBox1.Items[i]) - (Pos('">',Form1.ComboBox1.Items[i])+2)
        ) ;
        SQLQuery(dtssql, dts[i]);
        frxDBDatasets[i] := TfrxDBDataset.Create(Form1);
        frxDBDatasets[i].UserName        := dtsname;
        frxDBDatasets[i].CloseDataSource := True;
        frxDBDatasets[i].OpenDataSource  := True;
        frxDBDatasets[i].DataSet         := dts[i];
        Form1.frxReport.DataSets.Add(frxDBDatasets[i]);
    end;                                                    
    Form1.frxReport.LoadFromFile(ExtractFilePath(Application.ExeName)+'Report\test.fr3');
    Form1.frxReport.DesignReport;
    For i := 0 To Form1.ComboBox1.Items.Count - 1 Do
    frxDBDatasets[i].free ;
end;
procedure Form1_ComboBox1_OnChange (Sender: TObject);
begin
    Form1.Memo2.Text :=
    Copy(
    Form1.ComboBox1.Text,
    Pos('<dataset name"',Form1.ComboBox1.Text)+14,
    Pos('">',Form1.ComboBox1.Text)-(Pos('<dataset name"',Form1.ComboBox1.Text)+14),
    );
    Form1.Memo3.Text :=
    Copy(
    Form1.ComboBox1.Text,
    (Pos('">',Form1.ComboBox1.Text)+2),
    Pos('</dataset>',Form1.ComboBox1.Text) - (Pos('">',Form1.ComboBox1.Text)+2)
    );
    Form1.TableGrid1.ClearRows;
    Form1.TableGrid1.dbSQL := Form1.Memo3.Text;
    Form1.TableGrid1.dbSQLExecute;
end;
procedure Form1_OnShow (Sender: TObject; Action: string);
var
st_temp : String;
vt_name : tstringlist;
result_sql : String;
get_x,get_y : Integer;
para_x,para_y : Integer;
paraname : string;
dts : array[0..999] of ttoolbar;
dtsi: integer;
begin
    Form1.Memo1.Lines.LoadFromfile(ExtractFilePath(Application.exename)+'\sql.txt');
    //start
    st_temp := Form1.Memo1.Text ;
    result_sql := Form1.Memo1.Text;
    vt_name := tstringlist.Create ;
    vt_name.Clear ;
    Repeat
    begin
        get_x    := Pos('<dataset name"',st_temp);
        st_temp  := Copy(st_temp,get_x,Length(st_temp));
        get_y    := Pos('</dataset>',st_temp) ;
        paraname := Copy(st_temp,1,get_y+9);
        IF Pos(paraname,vt_name.Text) <= 0 Then
        vt_name.Add(paraname) ;
        Form1.ComboBox1.Items.add(paraname);
        st_temp  := copy(st_temp,get_y+10,Length(st_temp) );
    end;
    until Pos('<dataset name"',st_temp) <= 0;
end;
begin
end.
Post's attachments

Attachment icon Fix 2018-09-06 Update Example Report Flag ArrayDataset.zip 611.31 kb, 497 downloads since 2018-09-06 

My Visual Database : I Love You
Easy For Beginner Student For Me