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

📄 qexport4.pas

📁 Advanced.Export.Component.v4.01.rar,delphi 第三方控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
end;

{ TQExportFormats }

constructor TQExportFormats.Create;
begin
  inherited;
  ResetFormats;
  FKeepOriginalFormat := False;
  StoreSeparators;
end;

procedure TQExportFormats.Assign(Source: TPersistent);
begin
  if Source is TQExportFormats then begin
    IntegerFormat := (Source as TQExportFormats).IntegerFormat;
    FloatFormat := (Source as TQExportFormats).FloatFormat;
    DateFormat := (Source as TQExportFormats).DateFormat;
    TimeFormat := (Source as TQExportFormats).TimeFormat;
    DateTimeFormat := (Source as TQExportFormats).DateTimeFormat;
    CurrencyFormat := (Source as TQExportFormats).CurrencyFormat;
    BooleanTrue := (Source as TQExportFormats).BooleanTrue;
    BooleanFalse := (Source as TQExportFormats).BooleanFalse;
    NullString := (Source as TQExportFormats).NullString;

    DecimalSeparator := (Source as TQExportFormats).DecimalSeparator;
    ThousandSeparator := (Source as TQExportFormats).ThousandSeparator;
    DateSeparator := (Source as TQExportFormats).DateSeparator;
    TimeSeparator := (Source as TQExportFormats).TimeSeparator;
    FKeepOriginalFormat := (Source as TQExportFormats).KeepOriginalFormat;
    Exit;
  end;
  inherited;
end;

procedure TQExportFormats.ResetFormats;
begin
  FIntegerFormat := S_INTEGER_FORMAT;
  FFloatFormat := S_FLOAT_FORMAT;
  FDateFormat := DefaultDateFormat;
  FTimeFormat := DefaultTimeFormat;
  FDateTimeFormat := DefaultDateTimeFormat;
  FCurrencyFormat := DefaultCurrencyFormat;
  FBooleanTrue := S_BOOLEAN_TRUE;
  FBooleanFalse := S_BOOLEAN_FALSE;

  FDecimalSeparator := SysUtils.DecimalSeparator;
  FThousandSeparator := SysUtils.ThousandSeparator;
  FDateSeparator := SysUtils.DateSeparator;
  FTimeSeparator := SysUtils.TimeSeparator;
end;

procedure TQExportFormats.StoreSeparators;
begin
  FOldDecimalSeparator := SysUtils.DecimalSeparator;
  FOldThousandSeparator := SysUtils.ThousandSeparator;
  FOldDateSeparator := SysUtils.DateSeparator;
  FOldTimeSeparator := SysUtils.TimeSeparator;
end;

procedure TQExportFormats.RestoreSeparators;
begin
  SysUtils.DecimalSeparator := FOldDecimalSeparator;
  SysUtils.ThousandSeparator := FOldThousandSeparator;
  SysUtils.DateSeparator := FOldDateSeparator;
  SysUtils.TimeSeparator := FOldTimeSeparator;
end;

{Change Sysutils separators for export sequence}
procedure TQExportFormats.ApplyParams;
begin
  SysUtils.DecimalSeparator := FDecimalSeparator;
  SysUtils.ThousandSeparator := FThousandSeparator;
  SysUtils.DateSeparator := FDateSeparator;
  SysUtils.TimeSeparator := FTimeSeparator;
end;

procedure TQExportFormats.SetIntegerFormat(const Value: string);
begin
  if FIntegerFormat <> Value then
    if Value = EmptyStr
      then FIntegerFormat := S_INTEGER_FORMAT
      else FIntegerFormat := Value;
end;

procedure TQExportFormats.SetFloatFormat(const Value: string);
begin
  if FFloatFormat <> Value then
    {if Value = EmptyStr
      then FFloatFormat := S_FLOAT_FORMAT
      else FFloatFormat := Value;}
    FFloatFormat := Value; // ab
end;

procedure TQExportFormats.SetDateFormat(const Value: string);
begin
  if FDateFormat <> Value then
    if Value = EmptyStr
      then FDateFormat := DefaultDateFormat
      else FdateFormat := Value;
end;

procedure TQExportFormats.SetTimeFormat(const Value: string);
begin
  if FTimeFormat <> Value then
    if Value = EmptyStr
      then FTimeFormat := DefaultTimeFormat
      else FTimeFormat := Value;
end;

procedure TQExportFormats.SetDateTimeFormat(const Value: string);
begin
  if FDateTimeFormat <> Value then
    if Value = EmptyStr
      then FDateTimeFormat := DefaultDateTimeFormat
      else FDateTimeFormat := Value;
end;

procedure TQExportFormats.SetCurrencyFormat(const Value: string);
begin
  if FCurrencyFormat <> Value then
    if Value = EmptyStr
      then FCurrencyFormat := DefaultCurrencyFormat
      else FCurrencyFormat := Value;
end;

procedure TQExportFormats.SetBooleanTrue(const Value: QEString);
begin
  if FBooleanTrue <> Value then
    if Value = EmptyStr
      then FBooleanTrue := S_BOOLEAN_TRUE
      else FBooleanTrue := Value;
end;

procedure TQExportFormats.SetBooleanFalse(const Value: QEString);
begin
  if FBooleanFalse <> Value then
    if Value = EmptyStr
      then FBooleanFalse := S_BOOLEAN_FALSE
      else FBooleanFalse := Value;
end;

procedure TQExportFormats.SetNullString(const Value: QEString);
begin
  FNullString := Trim(Value);
end;

function TQExportFormats.IsDecimalSeparator: boolean;
begin
  Result := DecimalSeparator <> SysUtils.DecimalSeparator;
end;

function TQExportFormats.IsThousandSeparator: boolean;
begin
  Result := ThousandSeparator <> SysUtils.ThousandSeparator;
end;

function TQExportFormats.IsDateSeparator: boolean;
begin
  Result := DateSeparator <> SysUtils.DateSeparator;
end;

function TQExportFormats.IsTimeSeparator: boolean;
begin
  Result := TimeSeparator <> SysUtils.TimeSeparator;
end;

function TQExportFormats.IsIntegerFormatStored: boolean;
begin
  Result := AnsiCompareStr(FIntegerFormat, S_INTEGER_FORMAT) <> 0;
end;

function TQExportFormats.IsFloatFormatStored: boolean;
begin
  Result := AnsiCompareStr(FFloatFormat, S_FLOAT_FORMAT) <> 0;
end;

function TQExportFormats.IsDateFormatStored: boolean;
begin
  Result := AnsiCompareStr(FDateFormat, DefaultDateFormat) <> 0;
end;

function TQExportFormats.IsTimeFormatStored: boolean;
begin
  Result := AnsiCompareStr(FTimeFormat, DefaultTimeFormat) <> 0;
end;

function TQExportFormats.IsDateTimeFormatStored: boolean;
begin
  Result := AnsiCompareStr(FDateTimeFormat, DefaultDateTimeFormat) <> 0;
end;

function TQExportFormats.IsCurrencyFormatStored: boolean;
begin
  Result := AnsiCompareStr(FCurrencyFormat, DefaultCurrencyFormat) <> 0;
end;

function TQExportFormats.IsBooleanTrueStored: boolean;
begin
  Result := AnsiCompareStr(FBooleanTrue, S_BOOLEAN_TRUE) <> 0;
end;

function TQExportFormats.IsBooleanFalseStored: boolean;
begin
  Result := AnsiCompareStr(FBooleanFalse, S_BOOLEAN_FALSE) <> 0;
end;

{ TQExportColumn }

constructor TQExportColumn.Create(Collection: TCollection);
begin
  inherited;
  FTag := 0;
  if Collection is TQExportColumns then
    FColumns := Collection as TQExportColumns;
end;

function TQExportColumn.GetIsDefaultFormat: boolean;
begin
  Result := false;
  if FAllowFormat then
    case FColType of
      ectInteger, ectBigint: Result := FFormat = FColumns.FOwnerFormats.IntegerFormat;
      ectFloat: Result := FFormat = FColumns.FOwnerFormats.FloatFormat;
      ectDate: Result := FFormat = FColumns.FOwnerFormats.DateFormat;
      ectTime: Result := FFormat = FColumns.FOwnerFormats.TimeFormat;
      ectDateTime: Result := FFormat = FColumns.FOwnerFormats.DateTimeFormat;
      ectCurrency: Result := FFormat = FColumns.FOwnerFormats.CurrencyFormat;
    end;
end;

function TQExportColumn.GetDefaultFormat: string;
begin
  Result := EmptyStr;
  if FAllowFormat then
    case FColType of
      ectInteger, ectBigint: Result := FColumns.FOwnerFormats.IntegerFormat;
      ectFloat: Result := FColumns.FOwnerFormats.FloatFormat;
      ectDate: Result := FColumns.FOwnerFormats.DateFormat;
      ectTime: Result := FColumns.FOwnerFormats.TimeFormat;
      ectDateTime: Result := FColumns.FOwnerFormats.DateTimeFormat;
      ectCurrency: Result := FColumns.FOwnerFormats.CurrencyFormat;
    end;
end;

procedure TQExportColumn.SetDefaultFormat;
begin
  FFormat := GetDefaultFormat;
end;

{ TQExportColumns }

constructor TQExportColumns.Create(Holder: TPersistent; NormalFunc: TNormalFunc);
begin
  inherited Create(TQExportColumn);
  FHolder := Holder;
  FNormalFunc := NormalFunc;
end;

function TQExportColumns.Add: TQExportColumn;
begin
  Result := TQExportColumn(inherited Add);
end;

function TQExportColumns.GetColumn(Index: integer): TQExportColumn;
begin
  Result := TQExportColumn(inherited Items[Index]);
end;

procedure TQExportColumns.SetColumn(Index: integer; Value: TQExportColumn);
begin
  Items[Index].Assign(Value);
end;

procedure TQExportColumns.LoadOwnerProperties;
var
  PropInfo: PPropInfo;
begin
  PropInfo := GetPropInfo(FHolder.ClassInfo, 'ExportedFields');
  if Assigned(PropInfo) then
    FOwnerExportedFields := TStrings(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'ExportSource');
  if Assigned(PropInfo) then
    FOwnerExportSource := TQExportSource(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'DataSet');
  if Assigned(PropInfo) then
    FOwnerDataSet := TDataSet(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'CustomSource');
  if Assigned(PropInfo) then
    FOwnerCustomSource := TqeCustomSource4(GetOrdProp(FHolder, PropInfo));

  {$IFNDEF NOGUI}
  PropInfo := GetPropInfo(FHolder.ClassInfo, 'ListView');
  if Assigned(PropInfo) then
    FOwnerListView := TListView(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'DBGrid');
  if Assigned(PropInfo) then
    FOwnerDBGrid := TDBGrid(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'StringGrid');
  if Assigned(PropInfo) then
    FOwnerStringGrid := TStringGrid(GetOrdProp(FHolder, PropInfo));
  {$ENDIF}

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'OnlyVisibleFields');
  if Assigned(PropInfo) then
    FOwnerOnlyVisibleFields := Boolean(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'Formats');
  if Assigned(PropInfo) then
    FOwnerFormats := TQExportFormats(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'AutoCalcStrType');
  if Assigned(PropInfo) then
    FOwnerAutoCalcStrType := Boolean(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'CaptionRow');
  if Assigned(PropInfo) then
    FOwnerCaptionRow := Integer(GetOrdProp(FHolder, PropInfo))
  else FOwnerCaptionRow := -1;

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'UserFormats');
  if Assigned(PropInfo) then
    FOwnerUserFormats := TStrings(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'ColumnsWidth');
  if Assigned(PropInfo) then
    FOwnerColumnsWidth := TStrings(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'Captions');
  if Assigned(PropInfo) then
    FOwnerCaptions := TStrings(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'ColumnsAlign');
  if Assigned(PropInfo) then
    FOwnerColumnsAlign := TStrings(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'SkipRecCount');
  if Assigned(PropInfo) then
    FOwnerSkipRecCount := Integer(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'ExportRecCount');
  if Assigned(PropInfo) then
    FOwnerExportRecCount := Integer(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'ColumnsLength');
  if Assigned(PropInfo) then
    FOwnerColumnsLength := TStrings(GetOrdProp(FHolder, PropInfo));

  PropInfo := GetPropInfo(FHolder.ClassInfo, 'OnFetchedRecord');
  if Assigned(PropInfo) then
    FOwnerOnFetchedRecord := TExportedRecordEvent(GetMethodProp(FHolder, PropInfo));
end;

procedure TQExportColumns.Fill(BLOB: boolean);
var
  i, j: integer;
  FColCount: integer;
  FColumn: TQExportColumn;
begin
  LoadOwnerProperties;
  FColCount := 0;
  if FOwnerExportedFields.Count = 0 then begin
    case FOwnerExportSource of
      esDataSet:
        if Assigned(FOwnerDataSet) then
          FColCount := FOwnerDataSet.FieldCount;
      esCustom:
        if Assigned(FOwnerCustomSource) then
          FColCount := FOwnerCustomSource.ColCount;
      {$IFNDEF NOGUI}
      esListView:
        if Assigned(FOwnerListView) then
          FColCount := FOwnerListView.Columns.Count;
      esDBGrid:
        if Assigned(FOwnerDBGrid) then
          FColCount := FOwnerDBGrid.Columns.Count;
      esStringGrid:
        if Assigned(FOwnerStringGrid) then
          FColCount := FOwnerStringGrid.ColCount;
      {$ENDIF}
    end
  end
  else FColCount := FOwnerExportedFields.Count;
  for i := 0 to FColCount - 1 do  begin
    j := SetColumnNumber(i, BLOB);
    if  j = -1 then Continue;
    FColumn := Add;
    FColumn.Number := j;
  end;
  for i := 0 to Count - 1 do begin
    SetColumnName(i);
    SetColumnType(i);
    SetColumnCaption(i);
    SetColumnWidth(i);
    SetColumnFormat(i);
    SetColumnAlign(i);
    SetColumnSQLType(i);
    SetColumnIsString(i);
    SetColumnLength(i);
    SetColumnAllowFormat(i);
    SetColumnIsNumeric(i);
    SetColumnIsBlob(i);
    SetColumnIsMemo(i);
    SetColumnIsVisible(i);
  end;
end;

⌨️ 快捷键说明

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