?? qexport3.pas
字號:
for i := 0 to Count - 1 do
Items[i].Value := EmptyStr
end;
function TQExportRow.Last: TQExportCol;
begin
Result := TQExportCol(inherited Last);
end;
function TQExportRow.IndexOf(Item: TQExportCol): Integer;
begin
Result := inherited IndexOf(Item);
end;
function TQExportRow.Remove(Item: TQExportCol): Integer;
begin
Result := inherited Remove(Item);
end;
function TQExportRow.ColByName(const AName: string): TQExportCol;
var
i: integer;
begin
Result := nil;
for i := 0 to Count - 1 do
if AnsiCompareText(AName, Items[i].Name) = 0 then begin
Result := Items[i];
Exit;
end;
end;
function TQExportRow.Get(Index: Integer): TQExportCol;
begin
Result := TQExportCol(inherited Get(Index));
end;
procedure TQExportRow.Put(Index: Integer; const Value: TQExportCol);
begin
inherited Put(Index, Value);
end;
{ TQExport3 }
constructor TQExport3.Create(AOwner: TComponent);
begin
inherited;
FRecordCounter := 0;
FColumns := TQExportColumns.Create(Self, NormalString);
FExportSource := esDataSet;
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(con
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -