function TPub.StrReplaceString(var S: string; const Token, NewToken: string; bCaseSensitive: Boolean): Boolean;
var
I : Integer;
sFirstPart: string;
begin
if bCaseSensitive then
I := AnsiPos(Token, S)
else
I := AnsiPos(AnsiUpperCase(Token), AnsiUpperCase(S));
if I <> 0 then
begin
sFirstPart := Copy(S, 1, I - 1) + NewToken;
S := Copy(S, I + Length(Token), Maxint);
end;
Result := I <> 0;
if Result then
begin
StrReplaceString(S, Token, NewToken, bCaseSensitive);
S := sFirstPart + S;
end;
end;
procedure TPub.StrSimple_ReplaceString(var S: string; const Substr: string; index, Count: Integer);
begin
S := Format('%s%s%s',[Copy(S, 1, index - 1), Substr, Copy(S, index + Count, Maxint)]);
end;
function TPub.StrCompositeStrings(SL: TStrings; const Delimiter: string): string;
var
I: Integer;
begin
Result := '';
with SL do
begin
for I := 0 to Count - 2 do
Result := Result + Strings[I] + Delimiter;
if Count > 0 then
Result := Result + Strings[Count - 1];
end;
end;
function TPub.StrSafeLoadStrings(SL: TStrings; const Filename: string): Boolean;
begin
Result := False;
repeat
try
if not FileExists(Filename) then Exit;
SL.LoadFromFile(Filename);
Result := True;
Break;
except
Sleep(500);
end;
until False;
end;
procedure TPub.StrSafeSaveStrings(SL: TStrings; const Filename: string);
begin
ForceDirectories(ExtractFilePath(Filename));
repeat
try
SL.SaveToFile(Filename);
Break;
except
Sleep(500);
end;
until False;
end;
//以下字体
function TPub.FontToString(Font: TFont; bIncludeColor: Boolean): string;
var
sStyle: string;
begin
with Font do
begin
// convert font style to string
sStyle := '';
if (fsBold in Style) then
sStyle := sStyle + csfsBold;
if (fsItalic in Style) then
sStyle := sStyle + csfsItalic;
if (fsUnderline in Style) then
sStyle := sStyle + csfsUnderline;
if (fsStrikeOut in Style) then
sStyle := sStyle + csfsStrikeout;
if ((Length(sStyle) > 0) and ('|' = sStyle[1])) then
sStyle := Copy(sStyle, 2, Length(sStyle) - 1);
Result := Format('"%s", %d, [%s]',[name, Size, sStyle]);
if bIncludeColor then
Result := Result + Format(', [%s]',[ColorToString(Color)]);
end;
end;
procedure TPub.StringToFont(sFont: string; Font: TFont;
bIncludeColor: Boolean);
var
P : Integer;
sStyle: string; // Expected format:
begin // "Arial", 9, [Bold], [clRed]
with Font do //
try
// get font name
P := Pos(',', sFont);
name := Copy(sFont, 2, P - 3);
Delete(sFont, 1, P);
// get font size
P := Pos(',', sFont);
Size := StrToInt(Copy(sFont, 2, P - 2));
Delete(sFont, 1, P);
// get font style
P := Pos(',', sFont);
sStyle := '|' + Copy(sFont, 3, P - 4);
Delete(sFont, 1, P);
// get font color
if bIncludeColor then
Color := StringToColor(Copy(sFont, 3, Length(sFont) - 3));
// convert str font style to
// font style
Style := [];
if (Pos(csfsBold, sStyle) > 0) then
Style := Style + [fsBold];
if (Pos(csfsItalic, sStyle) > 0) then
Style := Style + [fsItalic];
if (Pos(csfsUnderline, sStyle) > 0) then
Style := Style + [fsUnderline];
if (Pos(csfsStrikeout, sStyle) > 0) then
Style := Style + [fsStrikeOut];
except
end;
end;
procedure TPub.ConWriteText(aContr: TControl;sText: string);
var
c:TCanvas;
begin
c:=TControlCanvas.Create;
TControlCanvas(c).Control := aContr;
c.Font.Size := 12;// Brush.Style:=bsClear;
c.Font.Color := clBlue;
//c.Pen.Color:=clBlue;
c.TextOut(1,1,sText);// Rectangle(5,5,15,15);
c.Free;
end;
procedure TPub.FileCopyDirectory(sDir, tDir: string);
var
aWaitForm: TForm;
RetValue: integer;
procedure MyCop