{******************************************} { } { FastReport v4.0 } { Server HTTP Forms } { } { Copyright (c) 1998-2007 } { by Alexander Fediachov, } { Fast Reports Inc. } { } {******************************************} unit frxServerForms; {$I frx.inc} interface uses Windows, 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: string); function GetHTML(Obj: TfrxDialogControl): String; 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: string); begin if Length(str) > 0 then begin Exp.Write(str[1], Length(str)); Exp.Write(#13#10, 2); end; end; 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'); FTemplate.Variables.AddVariable('TITLE', UTF8Encode(FDialog.Caption)); 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.Variables.AddVariable('CAPTION', UTF8Encode(FDialog.Caption)); 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('