{******************************************} { } { FastReport VCL } { Server HTTP Forms } { } { Copyright (c) 1998-2021 } { by Fast Reports Inc. } { } {******************************************} unit frxServerForms; {$I frx.inc} interface uses {$IFNDEF Linux} Windows, {$ELSE} LCLType, LCLIntf, LazHelper, {$ENDIF} Classes, SysUtils, Graphics, frxClass, frxDCtrl, frxUtils, frxExportMatrix, frxServerFormControls, frxUnicodeUtils, frxServerTemplates; type TfrxWebForm = class(Tobject) private Exp: TFileStream; FMatrix: TfrxIEMatrix; FDialog: TfrxDialogPage; FRepName: String; FSession: String; procedure WriteExpLn(const str: Ansistring);{$IFDEF Delphi12} overload; procedure WriteExpLn(const str: String); overload; {$ENDIF} function GetHTML(Obj: TfrxDialogControl): AnsiString; public constructor Create(Dialog: TfrxDialogPage; Session: String); destructor Destroy; override; procedure Prepare; procedure Clear; procedure SaveFormToFile(FName: String); property ReportName: String read FRepName write FRepName; end; implementation { TfrxWebForm } constructor TfrxWebForm.Create(Dialog: TfrxDialogPage; Session: String); begin FDialog := Dialog; FSession := Session; FMatrix := TfrxIEMatrix.Create(False, ''); FMatrix.ShowProgress := False; FMatrix.Inaccuracy := 10; FMatrix.AreaFill := True; FMatrix.FramesOptimization := False; end; destructor TfrxWebForm.Destroy; begin Clear; FMatrix.Free; inherited; end; procedure TfrxWebForm.Clear; begin FMatrix.Clear; end; procedure TfrxWebForm.WriteExpLn(const str: AnsiString); begin if Length(str) > 0 then begin Exp.Write(str[1], Length(str)); Exp.Write(#13#10, 2); end; end; {$IFDEF Delphi12} procedure TfrxWebForm.WriteExpLn(const str: String); begin WriteExpLn(UTF8Encode(str)); end; {$ENDIF} procedure TfrxWebForm.Prepare; var i: Integer; begin for i := 0 to FDialog.AllObjects.Count - 1 do FMatrix.AddDialogObject(FDialog.AllObjects[i]); FMatrix.Prepare; end; procedure TfrxWebForm.SaveFormToFile(FName: String); var i, x, y, fx, fy, dx, dy: Integer; drow, dcol: Integer; s, sb, st: String; //ss obj: TfrxIEMObject; FTemplate: TfrxServerTemplate; begin FTemplate := TfrxServerTemplate.Create; try try Exp := TFileStream.Create(FName, fmCreate); try FTemplate.SetTemplate('form_begin'); {$IFDEF Delphi12} FTemplate.Variables.AddVariable('TITLE', FDialog.Caption); FTemplate.Variables.AddVariable('CAPTION', FDialog.Caption); {$ELSE} FTemplate.Variables.AddVariable('TITLE', UTF8Encode(FDialog.Caption)); FTemplate.Variables.AddVariable('CAPTION', UTF8Encode(FDialog.Caption)); {$ENDIF} FTemplate.Variables.AddVariable('HTML_INIT', ''); FTemplate.Variables.AddVariable('HTML_CODE', ''); FTemplate.Variables.AddVariable('REPORT', FRepName); FTemplate.Variables.AddVariable('SESSION', FSession); FTemplate.Variables.AddVariable('BCOLOR', HTMLRGBColor(FDialog.Color)); FTemplate.Variables.AddVariable('COLSPAN', IntToStr(FMatrix.Width - 1)); FTemplate.Prepare; st := FTemplate.TemplateStrings.Text; WriteExpLn(st); for y := 0 to FMatrix.Height - 2 do begin drow := Round(FMatrix.GetYPosById(y + 1) - FMatrix.GetYPosById(y)); WriteExpLn('