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

📄 adfaxprn.pas

📁 测试用例
💻 PAS
📖 第 1 页 / 共 3 页
字号:
        Result := TApdFaxPrinterLog(Value.Components[I]);
        exit;
      end;
      Result := FindPrinterLog(Value.Components[I]);
    end;
  end;

begin
  Result := FindPrinterLog(Value);
end;


{ TApdFaxPrinterLog }

constructor TApdCustomFaxPrinterLog.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FLogFileName := afpDefFPLFileName;
end;

procedure TApdCustomFaxPrinterLog.UpdateLog(const LogCode: TFaxPLCode);
var
  LogFile : TextFile;
begin
  {Exit if no name specified}
  if (FLogFileName = '') then
    Exit;

  {Create or open the log file}
  try
    AssignFile(LogFile, FLogFileName);
    Append(LogFile);
  except
    on E : EInOutError do
      if E.ErrorCode = 2 then
        {File not found, open as new}
        Rewrite(LogFile)
      else
        {Unexpected error, forward the exception}
        raise;
  end;

  {Write the printer log entry}
  with TApdCustomFaxPrinter(FaxPrinter) do begin
    { TFaxPLCode = (lcStart, lcFinish, lcAborted, lcFailed); }
    case LogCode of
      lcStart  :
        WriteLn(LogFile, 'Printing ', FileName, ' started at ',
                DateTimeToStr(Now));
      lcFinish :
        WriteLn(LogFile, 'Printing ', FileName, ' finished at ',
                DateTimeToStr(Now), ^M^J);
      lcAborted:
        WriteLn(LogFile, 'Printing ', FileName, ' aborted at ',
                DateTimeToStr(Now), ^M^J);
      lcFailed :
        WriteLn(LogFile, 'Printing ', FileName, ' failed at ',
                DateTimeToStr(Now), ^M^J);
    end;
  end;

  Close(LogFile);
  if IOResult <> 0 then ;
end;

{ TApdCustomFaxPrinterMargin }

constructor TApdCustomFaxPrinterMargin.Create;
begin
  inherited Create;
  FCaption := '';
  FEnabled := False;
  FFont    := TFont.Create;
  Height   := 0;
end;

destructor TApdCustomFaxPrinterMargin.Destroy;
begin
  FFont.Free;
  inherited Destroy;
end;

procedure TApdCustomFaxPrinterMargin.SetFont(const NewFont: TFont);
begin
  { Set the font }
  FFont.Assign(NewFont);
end;

{ TApdAbstractFaxPrintStatus }

procedure TApdAbstractFaxPrinterStatus.SetPosition(const Value: TPosition);
begin
  if Value <> FPosition then begin
    FPosition := Value;
    if Assigned(FDisplay) then
      FDisplay.Position := Value;
  end;
end;

procedure TApdAbstractFaxPrinterStatus.SetCtl3D(const Value: Boolean);
begin
  if Value <> FCtl3D then begin
    FCtl3D := Value;
    if Assigned(FDisplay) then
      FDisplay.Ctl3D := Value;
  end;
end;

procedure TApdAbstractFaxPrinterStatus.SetVisible(const Value: Boolean);
begin
  if Value <> FVisible then begin
    FVisible := Value;
    if Assigned(FDisplay) then
      FDisplay.Visible := Value;
  end;
end;

procedure TApdAbstractFaxPrinterStatus.SetCaption(const Value: String);
begin
  if Value <> FCaption then begin
    FCaption := Value;
    if Assigned(FDisplay) then
      FDisplay.Caption := Value;
  end;
end;                                                                    

procedure TApdAbstractFaxPrinterStatus.GetProperties;
begin
  if Assigned(FDisplay) then begin
    Position := FDisplay.Position;
    Ctl3D := FDisplay.Ctl3D;
    Visible := FDisplay.Visible;
    Caption := FDisplay.Caption;                                      
  end;
end;

constructor TApdAbstractFaxPrinterStatus.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Caption := 'Print Status';                                          
  CreateDisplay;
  GetProperties;
end;

destructor TApdAbstractFaxPrinterStatus.Destroy;
begin
  DestroyDisplay;
  inherited Destroy;
end;

procedure TApdAbstractFaxPrinterStatus.Show;
begin
  if Assigned(FDisplay) then
    FDisplay.Show;
end;

{ TApdCustomFaxPrinter }

constructor TApdCustomFaxPrinter.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  { Design time properties }
  Caption              := afpDefFaxPrnCaption;
  FFaxFooter           := TApdFaxPrinterMargin.Create;
  FFaxHeader           := TApdFaxPrinterMargin.Create;
  FFileName            := '';
  FMultiPage           := afpDefFaxMultiPage;
  FPrintScale          := afpDefFaxPrintScale;
  FStatusDisplay       := nil;
  FFaxPrinterLog       := nil;

  { page margin settings }
  FFaxFooter.Caption   := afpDefFaxFooterCaption;
  FFaxFooter.Enabled   := afpDefFaxFooterEnabled;
  FFaxHeader.Caption   := afpDefFaxHeaderCaption;
  FFaxHeader.Enabled   := afpDefFaxHeaderEnabled;

  { run-time / read-only properties }
  FTotalFaxPages       := 0;
  FCurrentPrintingPage := 0;
  FLastPageToPrint     := 0;
  FFaxResolution       := afcDefResolution;
  FFaxWidth            := afcDefFaxCvtWidth;                         
  FFaxPrintProgress    := ppIdle;

  StatusDisplay        := SearchForDisplay(Owner);
  FaxPrinterLog        := SearchForPrinterLog(Owner);

  if not (csDesigning in ComponentState) then begin
    FPrintDialog := TPrintDialog.Create(Self);
    FFaxUnpack := TApdFaxUnpacker.Create(Self);
  end else begin
    FPrintDialog := nil;
    FFaxUnpack := nil;
  end;
end;

destructor TApdCustomFaxPrinter.Destroy;
begin
  FFaxHeader.Free;
  FFaxFooter.Free;

  if Assigned(FPrintDialog) then
    FPrintDialog.Free;
  if Assigned(FFaxUnpack) then
    FFaxUnpack.Free;

  inherited Destroy;
end;

procedure TApdCustomFaxPrinter.Notification(AComponent: TComponent;
                                 Operation: TOperation);
begin
  inherited Notification(AComponent, Operation);
  case Operation of
    opRemove :
      begin
        if AComponent = FStatusDisplay then
          FStatusDisplay := nil;
        if AComponent = FFaxPrinterLog then
          FFaxPrinterLog := nil;
      end;
    opInsert :
      begin
        if AComponent is TApdAbstractFaxPrinterStatus then begin
          if not Assigned(FStatusDisplay) then
            StatusDisplay := TApdAbstractFaxPrinterStatus(AComponent);
        end;
        if AComponent is TApdFaxPrinterLog then begin
          if not Assigned(FFaxPrinterLog) then
            FaxPrinterLog := TApdFaxPrinterLog(AComponent);
        end;
      end;
  end;
end;

procedure TApdCustomFaxPrinter.SetStatusDisplay(
              const Value: TApdAbstractFaxPrinterStatus);
begin
  if Value <> FStatusDisplay then begin
    FStatusDisplay  := Value;
    if Assigned(FStatusDisplay) then
      FStatusDisplay.FFaxPrinter := Self;
  end;
end;

procedure TApdCustomFaxPrinter.SetFaxFileName(const Value: String);
begin
  if FFileName <> Value then begin
    FFileName := Value;

    if not (csDesigning in ComponentState) then begin

      with FPrintDialog do begin
        { Set defaults for dialog }
        PrintRange := prAllPages;
        Options := [poPageNums];

        { Get the number of pages in the APF file }
        FFaxUnpack.InFileName := FFileName;
        FTotalFaxPages  := FFaxUnpack.NumPages;

        { Get detailed info for the fax }
        FFaxResolution := FFaxUnpack.FaxResolution;
        FFaxWidth  := FFaxUnpack.FaxWidth;

        { See if we have a good APF file }
        if FTotalFaxPages > 0 then begin
          FromPage := 1;
          MinPage := 1;
        end else begin
          FTotalFaxPages := 0;
          FromPage := 0;
          MinPage := 0;
        end;

        { Set page counts }
        MaxPage := FTotalFaxPages;
        ToPage := FTotalFaxPages;
        FFirstPageToPrint := FromPage;
        FLastPageToPrint := ToPage;
      end;
    end;
  end;
end;

procedure TApdCustomFaxPrinter.SetCaption(const Value: String);
begin
  { Set the job's print title in Printmanager}
  Printer.Title := Value;
end;

function TApdCustomFaxPrinter.GetCaption: String;
begin
  { Get the job's print title from print manager}
  Result := Printer.Title;
end;

procedure TApdCustomFaxPrinter.SetFaxPrintLog(const Value: TApdFaxPrinterLog);
begin
  if Value <> FFaxPrinterLog then begin
    FFaxPrinterLog := Value;
    if Assigned(FFaxPrinterLog) then
      FFaxPrinterLog.FFaxPrinter := Self;
  end;
end;

function TApdCustomFaxPrinter.ReplaceHFParams(Value: String;
                                              Page: Word): String;
var
  I, N: Word;
  T : String;
begin
  I := Pos('$', Value);
  while I > 0 do begin
    { total Length of tag }
    N := I;
    while (N <= Length(Value)) and (Value[N] <> ' ') do
      Inc(N);
    Dec(N, I);

    { preserve and delete the tag from the main string }
    T := Copy(Value, I, N);
    Delete(Value, I, N);

    { process the correct tag }
    case T[2] of
      'D', 'd' :
        T := DateToStr(Date);
      'T', 't' :
        T := TimeToStr(Time);
      'P', 'p' :
        T := IntToStr(Page);
      'N', 'n' :
        T := IntToStr(FTotalFaxPages);

⌨️ 快捷键说明

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