⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxjs_reportworks.pas

📁 Well known and usefull component for delphi 7
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      End;
   End;
End;

function __CommaString(const Parameters: array of Variant): Variant;
Var
   StrPos:Integer;
   Result1:String;
   Ws:String;

Begin
   Ws:=TDXJavaScript.ToString(Parameters[0]);
   Result1:=FetchByChar(Ws,'.',False);
   StrPos:=Length(Result1)-2;
   While StrPos>1 Do Begin
      Insert(',',Result1,StrPos);
      StrPos:=StrPos-3;
   End;
   Result:=Result1;
End;

function __FetchWord(const Parameters: array of Variant): Variant;
Var
   Ws:String;

Begin
   Ws:=TDXJavaScript.ToString(Parameters[0]);
   If Length(Parameters)=1 then Begin
      Result:=FetchByChar(Ws,#32,False);
   End
   Else Begin
      Result:=Fetch(Ws,TDXJavaScript.ToString(Parameters[1]),False);
   End;
End;

constructor TDXJS_REPORTWORKS.Create(AOwner: TComponent);
Begin
   inherited Create(AOwner);
   if (AOwner=Nil) or
      Not (AOwner is TForm) then Begin
      Raise Exception.Create('Parent must be TForm!');
      Exit;
   End;
   fFirstPage:=1;
   fLastPage:=999999;
   This:=Self;
   This.fStartDate:=Date;
   This.fEndDate:=This.fStartDate;
   This.fStringPrompt:='';
   fRefresh:=Nil;
   fDataSource:=Nil;
   fPreview:=False;
   WantedFields:=TStringList.Create;
   fWantedFields:=WantedFields;
   FieldValues:=TStringList.Create;
   if (csDesigning in ComponentState) or (csLoading in ComponentState) then Exit;
   fParent:=AOwner as TForm;
   fReportWorks:=TReportWorks.Create(fParent);
   fReportWorks.Parent:=fParent;
   fReportWorks.Hint:='';
   PublicAccessToReportWorks:=fReportWorks;
   JavaScript:=TDXJavaScript.Create(Nil);
   JavaScript.OnBeforeRun:=JSBeforeRun;
   JavaScript.OnAfterRun:=JSAfterRun;
   JavaScript.AddRoutine('InitializeEngine',@__InitializeEngine);
   JavaScript.AddRoutine('DrawLine',@__DrawLine);
   JavaScript.AddRoutine('NextLine',@__NextLine);
   JavaScript.AddRoutine('FontBold',@__FontBold);
   JavaScript.AddRoutine('FontItalic',@__FontItalic);
   JavaScript.AddRoutine('FontUnderline',@__FontUnderline);
   JavaScript.AddRoutine('FontRegular',@__FontRegular);
   JavaScript.AddRoutine('FontReset',@__FontRegular);
   JavaScript.AddRoutine('Print',@__Print);
   JavaScript.AddRoutine('PrintLn',@__PrintLn);
   JavaScript.AddRoutine('PrintCenter',@__PrintCenter);
   JavaScript.AddRoutine('ShadeLine',@__ShadeLine);
   JavaScript.AddRoutine('ResetColumns',@__ResetColumns);
   JavaScript.AddRoutine('NewColumn',@__NewColumn);
   JavaScript.AddRoutine('PrintColumn',@__PrintColumn);
   JavaScript.AddRoutine('NewPage',@__NewPage);
   JavaScript.AddRoutine('IsPageEnd',@__IsPageEnd);
   JavaScript.AddRoutine('GoToPageTop',@__GoToPageTop);
   JavaScript.AddRoutine('GoToPageBottom',@__GoToPageBottom);
   JavaScript.AddRoutine('PreviousLine',@__PreviousLine);
   JavaScript.AddRoutine('LineNumber',@__LineNumber);
   JavaScript.AddRoutine('PageNumber',@__PageNumber);
   JavaScript.AddRoutine('PageTotal',@__PageTotal);
   JavaScript.AddRoutine('GoToTab',@__GoToTab);
   JavaScript.AddRoutine('DeinitializeEngine',@__DeinitializeEngine);
   JavaScript.AddConstant('jLeft',0);
   JavaScript.AddConstant('jCenter',1);
   JavaScript.AddConstant('jRight',2);
   JavaScript.AddConstant('poLandScape',0);
   JavaScript.AddConstant('poPortrait',1);
   JavaScript.AddRoutine('SetSQL',@__SetSQL);
   JavaScript.AddRoutine('SetFields',@__SetFields);
   JavaScript.AddRoutine('GetField',@__GetField);
// v2.0 Features:
   JavaScript.AddRoutine('DatePrompt',@__DatePrompt);
   JavaScript.AddRoutine('StartDate',@__StartDate);
   JavaScript.AddRoutine('EndDate',@__EndDate);
   JavaScript.AddRoutine('StringPrompt',@__StringPrompt);
   JavaScript.AddRoutine('CommaString',@__CommaString);
   JavaScript.AddRoutine('FetchWord',@__FetchWord);
End;

destructor TDXJS_REPORTWORKS.Destroy;
Begin
   If Assigned(WantedFields) then Begin
      WantedFields.Free;
      WantedFields:=Nil;
   End;
   If Assigned(FieldValues) then Begin
      FieldValues.Free;
      FieldValues:=Nil;
   End;
   if Not (csDesigning in ComponentState) then Begin
      JavaScript.Free;
      JavaScript:=Nil;
   End;
   inherited Destroy;
End;

procedure TDXJS_REPORTWORKS.RunScript(Script:TStream);
{$ifdef VARIANTS}
Var
   MyNull:Variant;
{$endif}

Begin
   fReportWorks.Visible:=True;
   if fPreview then fReportWorks.Destination:=dPreview
   Else fReportWorks.Destination:=dPrinter;
   fReportWorks.CurrentPage:=1;
   fReportWorks.PrintPageFirst:=fFirstPage;
   fReportWorks.PrintPageLast:=fLastPage;
   JavaScript.LoadFromStream(Script);
   fReportWorks.Hint:='';
   fCanPrompt:=True;
   JavaScript.Run;
   If JavaScript.Compiled then Begin
{$ifdef VARIANTS}
      MyNull:=Null;
      JavaScript.CallFunction('Main',MyNull);
{$else}
      JavaScript.CallFunction('Main',Null);
{$endif}
      If Assigned(fGenerate) then fGenerate(Self);
   End;
   fParent.Refresh;
End;

Procedure TDXJS_REPORTWORKS.GotoFirstPage;
{$ifdef VARIANTS}
Var
   MyNull:Variant;
{$endif}

Begin
   fCanPrompt:=False;
   fReportWorks.FirstPage;
   If JavaScript.Compiled then Begin
{$ifdef VARIANTS}
      MyNull:=Null;
      JavaScript.CallFunction('Main',MyNull);
{$else}
      JavaScript.CallFunction('Main',Null);
{$endif}
      If Assigned(fGenerate) then fGenerate(Self);
   End;
End;

Procedure TDXJS_REPORTWORKS.GotoPriorPage;
{$ifdef VARIANTS}
Var
   MyNull:Variant;
{$endif}

Begin
   fCanPrompt:=False;
   fReportWorks.PreviousPage;
   If JavaScript.Compiled then Begin
{$ifdef VARIANTS}
      MyNull:=Null;
      JavaScript.CallFunction('Main',MyNull);
{$else}
      JavaScript.CallFunction('Main',Null);
{$endif}
      If Assigned(fGenerate) then fGenerate(Self);
   End;
End;

Procedure TDXJS_REPORTWORKS.GotoNextPage;
{$ifdef VARIANTS}
Var
   MyNull:Variant;
{$endif}

Begin
   fCanPrompt:=False;
   fReportWorks.NextPage;
   If JavaScript.Compiled then Begin
{$ifdef VARIANTS}
      MyNull:=Null;
      JavaScript.CallFunction('Main',MyNull);
{$else}
      JavaScript.CallFunction('Main',Null);
{$endif}
      If Assigned(fGenerate) then fGenerate(Self);
   End;
End;

Procedure TDXJS_REPORTWORKS.GotoLastPage;
{$ifdef VARIANTS}
Var
   MyNull:Variant;
{$endif}

Begin
   fCanPrompt:=False;
   fReportWorks.LastPage;
   If JavaScript.Compiled then Begin
{$ifdef VARIANTS}
      MyNull:=Null;
      JavaScript.CallFunction('Main',MyNull);
{$else}
      JavaScript.CallFunction('Main',Null);
{$endif}
      If Assigned(fGenerate) then fGenerate(Self);
   End;
End;

Function TDXJS_REPORTWORKS.getCurrentPage:Integer;
Begin
   if (csDesigning in ComponentState) or (csLoading in ComponentState)
      then Result:=0
   Else Result:=fReportWorks.CurrentPage;
End;

Procedure TDXJS_REPORTWORKS.setCurrentPage(value:Integer);
Begin
   if (csDesigning in ComponentState) or (csLoading in ComponentState) then Exit;
   fReportWorks.CurrentPage:=value;
End;

Function TDXJS_REPORTWORKS.TotalPages:Integer;
Begin
   Result:=fReportWorks.PageTotal;
End;

Procedure TDXJS_REPORTWORKS.SetZoom(Percent:Integer);
{$ifdef VARIANTS}
Var
   MyNull:Variant;
{$endif}

Begin
   fReportWorks.ZoomPercent:=Percent;
   If JavaScript.Compiled then Begin
{$ifdef VARIANTS}
      MyNull:=Null;
      JavaScript.CallFunction('Main',MyNull);
{$else}
      JavaScript.CallFunction('Main',Null);
{$endif}
      If Assigned(fGenerate) then fGenerate(Self);
   End;
End;

Procedure TDXJS_REPORTWORKS.JSBeforeRun(Sender:TObject);
Begin
//
End;

Procedure TDXJS_REPORTWORKS.JSAfterRun(Sender:TObject);
Begin
   If fReportWorks.Hint<>'' then Begin
      If Assigned(fOnSetSQL) then fOnSetSQL(fReportWorks.Hint);
      fReportWorks.Hint:='';
   End;
   If Assigned(fRefresh) then fRefresh(Self);
End;

Procedure TDXJS_REPORTWORKS.DatabaseJustOpened;
begin
   If JavaScript.Compiled then Begin
      JavaScript.CallFunction('DBOpen',[
         fDataSource.DataSet.RecordCount]);
   End;
End;

Procedure TDXJS_REPORTWORKS.DatabaseJustScrolled;
Var
   Loop:Integer;
{$ifdef VARIANTS}
   MyNull:Variant;
{$endif}

Begin
   If JavaScript.Compiled then Begin
      FieldValues.Clear;
      For Loop:=1 to WantedFields.Count do
          FieldValues.Add(
             fDataSource.DataSet.FieldbyName(WantedFields[Loop-1]).AsString);
{$ifdef VARIANTS}
      MyNull:=Null;
      JavaScript.CallFunction('DBNextRow',MyNull);
{$else}
      JavaScript.CallFunction('DBNextRow',Null);
{$endif}
   End;
End;

Procedure TDXJS_REPORTWORKS.ReportDone;
{$ifdef VARIANTS}
Var
   MyNull:Variant;
{$endif}

Begin
{$ifdef VARIANTS}
   MyNull:=Null;
   If JavaScript.Compiled then JavaScript.CallFunction('Finished',MyNull);
{$else}
   If JavaScript.Compiled then JavaScript.CallFunction('Finished',Null);
{$endif}
End;

Procedure TDXJS_REPORTWORKS.SetDateRange(StartDate,EndDate:TDateTime);
Begin
   fStartDate:=StartDate;
   fEndDate:=EndDate;
End;

Procedure TDXJS_REPORTWORKS.SetStringPrompt(S:String);
Begin
   fStringPrompt:=S;
End;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -