📄 qimport3.pas
字号:
ResultPtr := PWideChar(ResultStr);
SourcePtr := PWideChar(S);
C := Search[1];
while True do
begin
LowerCaseFlag := False;
if IsCharLowerW(SourcePtr^) then
begin
CharUpperBuffW(SourcePtr, 1);
LowerCaseFlag := True;
end;
while (SourcePtr^ <> C) and (SourcePtr^ <> #0) do
begin
if LowerCaseFlag then
CharLowerBuffW(SourcePtr, 1);
ResultPtr^ := SourcePtr^;
Inc(ResultPtr);
Inc(SourcePtr);
LowerCaseFlag := False;
if IsCharLowerW(SourcePtr^) then
begin
CharUpperBuffW(SourcePtr, 1);
LowerCaseFlag := True;
end;
end;
if LowerCaseFlag then
CharLowerBuffW(SourcePtr, 1);
if SourcePtr^ = #0 then
Break
else
begin
SourceMatchPtr := SourcePtr + 1;
SearchMatchPtr := PWideChar(Search) + 1;
LowerCaseFlag := False;
if IsCharLowerW(SourceMatchPtr^) then
begin
CharUpperBuffW(SourceMatchPtr, 1);
LowerCaseFlag := True;
end;
while (SourceMatchPtr^ = SearchMatchPtr^) and (SearchMatchPtr^ <> #0) do
begin
if LowerCaseFlag then
CharLowerBuffW(SourceMatchPtr, 1);
Inc(SourceMatchPtr);
Inc(SearchMatchPtr);
LowerCaseFlag := False;
if IsCharLowerW(SourceMatchPtr^) then
begin
CharUpperBuffW(SourceMatchPtr, 1);
LowerCaseFlag := True;
end;
end;
if LowerCaseFlag then
CharLowerBuffW(SourceMatchPtr, 1);
if SearchMatchPtr^ = #0 then
begin
Move((@Replace[1])^, ResultPtr^, ReplaceLength * 2);
Inc(SourcePtr, SearchLength);
Inc(ResultPtr, ReplaceLength);
if not (rfReplaceAll in Flags) then
begin
while SourcePtr^ <> #0 do
begin
ResultPtr^ := SourcePtr^;
Inc(ResultPtr);
Inc(SourcePtr);
end;
Break;
end;
end
else
begin
ResultPtr^ := SourcePtr^;
Inc(ResultPtr);
Inc(SourcePtr);
end;
end;
end;
ResultPtr^ := #0;
S := ResultStr;
SetLength(S, Length(S));
end;
procedure WideStrReplaceCS(var S: WideString; const Search, Replace: WideString; Flags: TReplaceFlags);
var
ResultStr: WideString;
SourcePtr: PWideChar;
SourceMatchPtr: PWideChar;
SearchMatchPtr: PWideChar;
ResultPtr: PWideChar;
SearchLength,
ReplaceLength,
ResultLength: Integer;
C: WideChar;
begin
SearchLength := Length(Search);
ReplaceLength := Length(Replace);
if Length(Search) >= ReplaceLength then
ResultLength := Length(S)
else
ResultLength := ((Length(S) div Length(Search)) + 1) * Length(Replace);
SetLength(ResultStr, ResultLength);
ResultPtr := PWideChar(ResultStr);
SourcePtr := PWideChar(S);
C := Search[1];
while True do
begin
while (SourcePtr^ <> C) and (SourcePtr^ <> #0) do
begin
ResultPtr^ := SourcePtr^;
Inc(ResultPtr);
Inc(SourcePtr);
end;
if SourcePtr^ = #0 then
Break
else
begin
SourceMatchPtr := SourcePtr + 1;
SearchMatchPtr := PWideChar(Search) + 1;
while (SourceMatchPtr^ = SearchMatchPtr^) and (SearchMatchPtr^ <> #0) do
begin
Inc(SourceMatchPtr);
Inc(SearchMatchPtr);
end;
if SearchMatchPtr^ = #0 then
begin
Move((@Replace[1])^, ResultPtr^, ReplaceLength * 2);
Inc(SourcePtr, SearchLength);
Inc(ResultPtr, ReplaceLength);
if not (rfReplaceAll in Flags) then
begin
while SourcePtr^ <> #0 do
begin
ResultPtr^ := SourcePtr^;
Inc(ResultPtr);
Inc(SourcePtr);
end;
Break;
end;
end
else
begin
ResultPtr^ := SourcePtr^;
Inc(ResultPtr);
Inc(SourcePtr);
end;
end;
end;
ResultPtr^ := #0;
S := ResultStr;
SetLength(S, Length(S));
end;
procedure WideStrReplace(var S: WideString; const Search, Replace: WideString;
Flags: TReplaceFlags);
begin
if (S <> '') and (Search <> '') then
begin
if rfIgnoreCase in Flags then
WideStrReplaceCI(S, Search, Replace, Flags)
else
WideStrReplaceCS(S, Search, Replace, Flags);
end;
end;
{$ENDIF}
function QImportLocale: TQImportLocale;
begin
if Locale = nil then
Locale := TQImportLocale.Create;
Result := Locale;
end;
function QImportLoadStr(ID: Integer): string;
begin
Result := QImportLocale.LoadStr(ID);
end;
{ TQImportFormats }
constructor TQImportFormats.Create;
begin
inherited;
FDecimalSeparator := SysUtils.DecimalSeparator;
FThousandSeparator := SysUtils.ThousandSeparator;
FShortDateFormat := SysUtils.ShortDateFormat;
FLongDateFormat := SysUtils.LongDateFormat;
FDateSeparator := SysUtils.DateSeparator;
FShortTimeFormat := SysUtils.ShortTimeFormat;
FLongTimeFormat := SysUtils.LongTimeFormat;
FTimeSeparator := SysUtils.TimeSeparator;
FBooleanTrue := TStringList.Create;
FBooleanTrue.Add(QImportLoadStr(QID_BooleanTrue));
FBooleanFalse := TStringList.Create;
FBooleanFalse.Add(QImportLoadStr(QID_BooleanFalse));
FNullValues := TStringList.Create;
FNullValues.Add(QImportLoadStr(QID_NullValue));
end;
destructor TQImportFormats.Destroy;
begin
FBooleanTrue.Free;
FBooleanFalse.Free;
FNullValues.Free;
inherited;
end;
procedure TQImportFormats.Assign(Source: TPersistent);
begin
if Source is TQImportFormats then
begin
DecimalSeparator := (Source as TQImportFormats).DecimalSeparator;
ThousandSeparator := (Source as TQImportFormats).ThousandSeparator;
ShortDateFormat := (Source as TQImportFormats).ShortDateFormat;
LongDateFormat := (Source as TQImportFormats).LongDateFormat;
DateSeparator := (Source as TQImportFormats).DateSeparator;
ShortTimeFormat := (Source as TQImportFormats).ShortTimeFormat;
LongTimeFormat := (Source as TQImportFormats).LongTimeFormat;
TimeSeparator := (Source as TQImportFormats).TimeSeparator;
BooleanTrue := (Source as TQImportFormats).BooleanTrue;
BooleanFalse := (Source as TQImportFormats).BooleanFalse;
NullValues := (Source as TQImportFormats).NullValues;
Exit;
end;
inherited Assign(Source);
end;
procedure TQImportFormats.StoreFormats;
begin
FOldDecimalSeparator := SysUtils.DecimalSeparator;
FOldThousandSeparator := SysUtils.ThousandSeparator;
FOldShortDateFormat := SysUtils.ShortDateFormat;
FOldLongDateFormat := SysUtils.LongDateFormat;
FOldDateSeparator := SysUtils.DateSeparator;
FOldShortTimeFormat := SysUtils.ShortTimeFormat;
FOldLongTimeFormat := SysUtils.LongTimeFormat;
FOldTimeSeparator := SysUtils.TimeSeparator;
end;
procedure TQImportFormats.RestoreFormats;
begin
SysUtils.DecimalSeparator := FOldDecimalSeparator;
SysUtils.ThousandSeparator := FOldThousandSeparator;
SysUtils.ShortDateFormat := FOldShortDateFormat;
SysUtils.LongDateFormat := FOldLongDateFormat;
SysUtils.DateSeparator := FOldDateSeparator;
SysUtils.ShortTimeFormat := FOldShortTimeFormat;
SysUtils.LongTimeFormat := FOldLongTimeFormat;
SysUtils.TimeSeparator := FOldTimeSeparator;
end;
procedure TQImportFormats.ApplyParams;
begin
SysUtils.DecimalSeparator := Char(FDecimalSeparator);
SysUtils.ThousandSeparator := Char(FThousandSeparator);
SysUtils.ShortDateFormat := String(FShortDateFormat);
SysUtils.LongDateFormat := String(FLongDateFormat);
SysUtils.DateSeparator := Char(FDateSeparator);
SysUtils.ShortTimeFormat := String(FShortTimeFormat);
SysUtils.LongTimeFormat := String(FLongTimeFormat);
SysUtils.TimeSeparator := Char(FTimeSeparator);
end;
function TQImportFormats.IsDecimalSeparator: boolean;
begin
Result := FDecimalSeparator <> SysUtils.DecimalSeparator;
end;
function TQImportFormats.IsThousandSeparator: boolean;
begin
Result := FThousandSeparator <> SysUtils.ThousandSeparator;
end;
function TQImportFormats.IsShortDateFormat: Boolean;
begin
Result := FShortDateFormat <> SysUtils.ShortDateFormat;
end;
function TQImportFormats.IsLongDateFormat: Boolean;
begin
Result := FLongDateFormat <> SysUtils.LongDateFormat;
end;
function TQImportFormats.IsDateSeparator: Boolean;
begin
Result := FDateSeparator <> SysUtils.DateSeparator;
end;
function TQImportFormats.IsShortTimeFormat: Boolean;
begin
Result := FShortTimeFormat <> SysUtils.ShortTimeFormat;
end;
function TQImportFormats.IsLongTimeFormat: Boolean;
begin
Result := FLongTimeFormat <> SysUtils.LongTimeFormat;
end;
function TQImportFormats.IsTimeSeparator: Boolean;
begin
Result := FTimeSeparator <> SysUtils.TimeSeparator;
end;
procedure TQImportFormats.SetBooleanTrue(const Value: TStrings);
begin
FBooleanTrue.Assign(Value);
end;
procedure TQImportFormats.SetBooleanFalse(const Value: TStrings);
begin
FBooleanFalse.Assign(Value);
end;
procedure TQImportFormats.SetNullValues(const Value: TStrings);
begin
FNullValues.Assign(Value);
end;
{ TQImport3 }
constructor TQImport3.Create(AOwner: TComponent);
begin
inherited;
{$IFNDEF NOGUI}
FGridCaptionRow := -1;
FGridStartRow := -1;
{$ENDIF}
FErrors := TStringList.Create;
FMap := TStringList.Create;
FFormats := TQImportFormats.Create;
FFieldFormats := TQImportFieldFormats.Create(Self);
FImportRow := TQImportRow.Create(Self);
FImportGenerators := TQImportGenerators.Create;
FImportRecCount := 0;
FCommitRecCount := 1000;
FCommitAfterDone := False;
FSkipFirstRows := 0;
FSkipFirstCols := 0;
FImportedRecs := 0;
FCanceled := false;
FErrorLog := false;
FErrorLogFileName:= 'error.log';
FRewriteErrorLogFile := true;
FShowErrorLog := false;
// FSQLLog := false;
// FSQLLogFileRewrite := true;
// FSQL := nil;
FTotalRecCount := 0;
FAddType := qatInsert;
FImportDestination := qidDataSet;
FImportMode := qimInsertAll;
FKeyColumns := TStringList.Create;
FMappedColumns := TStringList.Create;
FIsCSV := False;
FLastAction := qiaNone;
FAllowDuplicates := True;
FCustomImportMode := False;
end;
destructor TQImport3.Destroy;
begin
FImportGenerators.Free;
FImportRow.Free;
FFieldFormats.Free;
FFormats.Free;
FMap.Free;
FErrors.Free;
FKeyColumns.Free;
FMappedColumns.Free;
inherited;
end;
function TQImport3.Execute: boolean;
begin
{$IFDEF ADVANCED_DATA_IMPORT_TRIAL_VERSION}
if not IsIDERuning then
ShowAboutForm;
{$ENDIF}
Result := CheckProperties;
BeforeImport;
try
DoBeginImport;
DoImport;
finally
try
DoEndImport
finally
AfterImport;
end;
end;
end;
procedure TQImport3.ImportToCSV(Stream: TStream; Comma, Quote: AnsiChar);
begin
{$IFDEF ADVANCED_DATA_IMPORT_TRIAL_VERSION}
if not IsIDERuning then
ShowAboutForm;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -