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

📄 qexport3.pas

📁 DELPHI开发VCL
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  FExportedFields := TStringList.Create;
  FHeader := TStringList.Create;
  FCaptions := TStringList.Create;
  FAllowCaptions := true;
  FFooter := TStringList.Create;
  FFormats := TQExportFormats.Create;
  FUserFormats := TStringList.Create;
  FColumnsWidth := TStringList.Create;
  FColumnsAlign := TStringList.Create;
  FColumnsLength := TStringList.Create;

  FExportRow := TQExportRow.Create(Columns, Formats, GetColData);

  FCurrentRecordOnly := false;
  FGoToFirstRecord := true;
  FSkipRecCount := 0;
  FExportRecCount := 0;
  FOnlyVisibleFields := false;
  FAutoCalcStrType := false;
  FAutoCalcColWidth := false;
  FCaptionRow := -1;
  FExportEmpty := true;

  FAborted := false;

  F_Version := S_VERSION;
  FAbout := S_ABOUT;
end;

destructor TQExport3.Destroy;
begin
  FExportRow.Free;
  FColumns.Free;

  FExportedFields.Free;
  FHeader.Free;
  FCaptions.Free;
  FFooter.Free;
  FFormats.Free;
  FUserFormats.Free;
  FColumnsWidth.Free;
  FColumnsAlign.Free;
  FColumnsLength.Free;
  inherited;
end;

procedure TQExport3.Execute;
begin
end;

procedure TQExport3.ExportToStream(AStream: TStream);
begin
  FWriter := GetWriterClass.Create(Self, AStream);
  try
    DoExport;
  finally
    FWriter.Free;
  end;
end;

procedure TQExport3.Abort;
begin
  FAborted := true;
end;

procedure TQExport3.Notification(AComponent: TComponent; Operation: TOperation);
begin
  inherited;
  if Operation = opRemove then begin
    if AComponent = FDataSet then FDataSet := nil;
    if AComponent = FCustomSource then FCustomSource := nil;
    {$IFNDEF NOGUI}
    if AComponent = FListView then FListView := nil;
    if AComponent = FDBGrid then FDBGrid := nil;
    if AComponent = FStringGrid then FStringGrid := nil;
    {$ENDIF}
  end;
end;

procedure TQExport3.LoadPropertiesFromFile(const FileName: string);
var
  IniFile: TIniFile;
begin
  IniFile := TIniFile.Create(FileName);
  try
    LoadProperties(IniFile);
  finally
    IniFile.Free;
  end;
end;

procedure TQExport3.SavePropertiesToFile(const FileName: string);
var
  IniFile: TIniFile;
begin
  IniFile := TIniFile.Create(FileName);
  try
    SaveProperties(IniFile);
  finally
    IniFile.Free;
  end;
end;

procedure TQExport3.DisableControls;
begin
  QExportDisableControls(FExportSource, FDataSet, FCustomSource
    {$IFNDEF NOGUI}, FDBGrid, FListView, FStringGrid{$ENDIF});
end;

procedure TQExport3.EnableControls;
begin
  QExportEnableControls(FExportSource, FDataSet, FCustomSource
    {$IFNDEF NOGUI}, FDBGrid, FListView, FStringGrid{$ENDIF});
end;

procedure TQExport3.First;
begin
  FRecordCounter := 0;
  QExportFirst(FExportSource, FDataSet, FCustomSource
    {$IFNDEF NOGUI}, FDBGrid, FListView, FStringGrid{$ENDIF});
end;

procedure TQExport3.Next;
begin
  QExportNext(FExportSource, FDataSet, FCustomSource,
    {$IFNDEF NOGUI}FDBGrid, FListView, FStringGrid,{$ENDIF}FRecordCounter);
end;

procedure TQExport3.Skip(Count: integer);
begin
  QExportSkip(FExportSource, FDataSet, FCustomSource,
    {$IFNDEF NOGUI}FDBGrid, FListView, FStringGrid,{$ENDIF}
    FSkipRecCount, FOnSkippedRecord, Self, FRecordCounter)
end;

function TQExport3.EndOfFile: boolean;
begin
  Result := QExportEof(ExportSource, DataSet, CustomSource,
    {$IFNDEF NOGUI}DBGrid, ListView, StringGrid,{$ENDIF} RecordCounter,
    ExportRecCount, SkipRecCount);
end;

function TQExport3.GetBookmark: TBookmark;
begin
  Result := QExportGetBookmark(FExportSource, FDataSet, FCustomSource
    {$IFNDEF NOGUI}, FDBGrid, FListView, FStringGrid{$ENDIF});
end;

procedure TQExport3.GoToBookmark(Bookmark: TBookmark);
begin
  FRecordCounter := 0;
  QExportGoToBookmark(FExportSource, FDataSet, FCustomSource,
  {$IFNDEF NOGUI}FDBGrid, FListView, FStringGrid,{$ENDIF} Bookmark);
end;

procedure TQExport3.FreeBookmark(Bookmark: TBookmark);
begin
  QExportFreeBookmark(FExportSource, FDataSet, {$IFNDEF NOGUI}FDBGrid,
    FListView, FStringGrid,{$ENDIF} Bookmark);
end;

function TQExport3.IsEmpty: boolean;
begin
  Result := QExportIsEmpty(FExportSource, FDataSet, FCustomSource
    {$IFNDEF NOGUI}, FDBGrid, FListView, FStringGrid{$ENDIF});
end;

function TQExport3.IsActive: boolean;
begin
  Result := QExportIsActive(FExportSource, FDataSet, FCustomSource
    {$IFNDEF NOGUI}, FDBGrid, FListView, FStringGrid{$ENDIF});
end;

function TQExport3.GetColCaption(Index: integer): string;
begin
  Result := NormalString(Columns[Index].Caption);
end;

function TQExport3.GetColData(ExportCol: TQExportCol): string;
begin
  Result := ExportCol.Value;
end;

function TQExport3.NormalString(const S: string): string;
begin
  Result := S;
end;

procedure TQExport3.FillExportRow;
var
  i: integer;
  str: string;
  wstr: WideString;
begin
  for i := 0 to FColumns.Count - 1 do
  begin
    str := QExportGetColData(FExportSource, FDataSet, FCustomSource,
      {$IFNDEF NOGUI}FDBGrid, FListView, FStringGrid,{$ENDIF}
      FColumns, FFormats, FColumns.FNormalFunc, i, FRecordCounter,
      FSkipRecCount, false);
    wstr := str;
    if Assigned(FOnGetExportText) then
      FOnGetExportText(Self, i, wstr);
    FExportRow.SetValue(Columns[i].Name, wstr, wstr = str);
  end;
end;

function TQExport3.GetDataRow(NeedFormat: boolean): string;
var
  i: integer;
begin
  Result := EmptyStr;
  for i := 0 to FExportRow.Count - 1 do
    Result := Result + FExportRow[i].GetExportedValue(NeedFormat);
end;

function TQExport3.GetCaptionRow: string;
var
  i: integer;
begin
  Result := EmptyStr;
  for i := 0 to Columns.Count - 1 do
    Result := Result + GetColCaption(i);
end;

procedure TQExport3.DoExport;
var
  AcceptRow: boolean;
begin
  FRecordCounter := 0;
  CheckExportSource;
  if not IsActive
    then raise Exception.CreateFmt({$IFDEF WIN32}QExportLoadStr(QEM_ExportSourceNotActive){$ENDIF}
                                   {$IFDEF LINUX}QEM_ExportSourceNotActive{$ENDIF},
                                   [QExportSourceAsString(FExportSource)]);
  if (not FExportEmpty) and IsEmpty
    then raise Exception.CreateFmt({$IFDEF WIN32}QExportLoadStr(QEM_ExportSourceEmpty){$ENDIF}
                                   {$IFDEF LINUX}QEM_ExportSourceEmpty{$ENDIF},
                                   [QExportSourceAsString(FExportSource)]);
  DisableControls;
  try
    BeginExport;
    if Aborted then Exit;
    if AutoCalcColWidth then
      Columns.AutoCalcColWidth;
    if Aborted then Exit;
    try
      if FAllowCaptions then
        WriteCaptionRow;
      if Aborted then Exit;
      if FGoToFirstRecord then First;
      BeforeExport;
      if Aborted then Exit;
      Skip(SkipRecCount);
      if Aborted then Exit;
      RecordCounter := 0;
      while not EndOfFile and
        ((FExportRecCount = 0) or
         (FRecordCounter < FExportRecCount)) do
      begin
        if FAborted and not CanContinue then Break;
        AcceptRow := true;
        FillExportRow;
        if Assigned(FOnBeforeExportRow) then
          FOnBeforeExportRow(Self, FExportRow, AcceptRow);
        if AcceptRow then begin
          WriteDataRow;
          if Assigned(FOnExportedRecord)
            then FOnExportedRecord(Self, FRecordCounter);
        end;
        if FCurrentRecordOnly
          then Break
          else Next;
{$IFDEF WIN32}
        Sleep(0);
{$ENDIF}        
      end;
      AfterExport;
    finally
      EndExport;
    end;
  finally
    EnableControls;
  end;
end;

procedure TQExport3.SetExportedFields(const Value: TStrings);
begin
  FExportedFields.Assign(Value);
end;

procedure TQExport3.BeginExport;
var
  i: integer;
begin
  CheckTrial;
  Columns.Clear;
  Columns.Fill(false);

  FExportRow.Clear;
  FExportRow.FIndex.Clear;

  for i := 0 to Columns.Count - 1 do begin
    FExportRow.Add(Columns[i].Name, i);
    FExportRow.FIndex.AddObject(Columns[i].Name, TObject(i));
  end;
  FExportRow.FIndex.Sort;

  FAborted := false;

  {$IFNDEF NOGUI}
  case FExportSource of
    esListView: begin
      FSkipRecCount := MinimumInt(FSkipRecCount, FListView.Items.Count);
      if FExportRecCount > 0 then
        FExportRecCount := MinimumInt(FExportRecCount, FListView.Items.Count);
    end;
  end;
  {$ENDIF}
  if Assigned(FOnBeginExport) then FOnBeginExport(Self);
end;

procedure TQExport3.EndExport;
begin
  if Assigned(FOnEndExport) then FOnEndExport(Self);
end;

procedure TQExport3.SetCaptions(const Value: TStrings);
begin
  FCaptions.Assign(Value);
end;

procedure TQExport3.SetFooter(const Value: TStrings);
begin
  FFooter.Assign(Value);
end;

procedure TQExport3.SetHeader(const Value: TStrings);
begin
  FHeader.Assign(Value);
end;

procedure TQExport3.SetUserFormats(const Value: TStrings);
begin
  FUserFormats.Assign(Value);
end;

procedure TQExport3.SetFormats(const Value: TQExportFormats);
begin
  FFormats.Assign(Value);
end;

procedure TQExport3.AfterExport;
begin
  // do nothing
end;

procedure TQExport3.BeforeExport;
begin
// do nothing
end;

function TQExport3.GetSpecialCharacters: TSpecialCharacters;
begin
  Result := [];
end;

procedure TQExport3.SetColumnsWidth(const Value: TStrings);
begin
  FColumnsWidth.Assign(Value);
end;

procedure TQExport3.SetColumnsAlign(const Value: TStrings);
begin
  FColumnsAlign.Assign(Value);
end;

procedure TQExport3.SetColumnsLength(const Value: TStrings);
begin
  FColumnsLength.Assign(Value);
end;

procedure TQExport3.CheckExportSource;
begin
  QExportCheckSource(ExportSource, FDataSet, FCustomSource
    {$IFNDEF NOGUI}, FDBGrid, FListView, FStringGrid{$ENDIF});
end;

function TQExport3.GetWriterClass: TQExportWriterClass;
begin
  Result := TQExportWriter;
end;

function TQExport3.GetWriter: TQExportWriter;
begin
  Result := TQExportWriter(FWriter);
end;

procedure TQExport3.WriteCaptionRow;
begin

end;

procedure TQExport3.WriteDataRow;
begin
end;

function TQExport3.CanContinue: boolean;
begin
  Result := not FAborted;
  if Assigned(FOnStopExport) then FOnStopExport(Self, Result);
  FAborted := not Result;
end;

procedure TQExport3.GetCellParams(RecNo, ColNo: integer; const Value: string;
  var Align: TQExportColAlign; AFont: TFont; var Background: TColor);
begin
  if Assigned(FOnGetCellParams) then
    FOnGetCellParams(Self, RecNo, ColNo, Value, Align, AFont, Background);
end;

procedure TQExport3.LoadProperties(IniFile: TIniFile);
var i: Integer;
begin
  with IniFile do begin
    //--- General
    GoToFirstRecord := ReadBool(S_GENERAL, S_GoToFirstRecord, GoToFirstRecord);
    ExportEmpty := ReadBool(S_GENERAL, S_ExportEmpty, ExportEmpty);
    CurrentRecordOnly := ReadBool(S_GENERAL, S_CurrentRecordOnly, CurrentRecordOnly);
    ExportRecCount := Re

⌨️ 快捷键说明

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