📄 wwsystem.pas
字号:
end;
function wwStrToTime(const S: string): boolean;
var
Pos: Integer;
Time: TDateTime;
begin
Pos := 1;
result:= ScanTime(S, Pos, Time) and (Pos > Length(S));
end;
function wwStrToDateTime(const S: string): boolean;
var
Pos: Integer;
Date, Time: TDateTime;
begin
Pos := 1;
Time := 0;
result:= ScanDate(S, Pos, Date) and
ScanTime(S, Pos, Time) and (Pos > Length(S))
end;
function wwStrToDateTimeVal(const S: string): TDateTime;
var
Pos: Integer;
Date, Time: TDateTime;
begin
Pos := 1;
Time := 0;
if ScanDate(S, Pos, Date) and
ScanTime(S, Pos, Time) and (Pos > Length(S)) then
begin
Result := (Date + Time);
end
else result:= 0;
end;
function wwStrToDateVal(const S: string): TDateTime;
var
Pos: Integer;
Date: TDateTime;
begin
Pos := 1;
if ScanDate(S, Pos, Date) then
begin
Result := Date;
end
else result:= 0;
end;
function wwStrToTimeVal(const S: string): TDateTime;
var
Pos: Integer;
Time: TDateTime;
begin
Pos := 1;
if ScanTime(S, Pos, Time) and (Pos > Length(S)) then
Result:= Time
else Result:= 0;
end;
function wwStrToInt(const S: string): boolean;
var i: integer;
begin
result:= True;
for i:= 1 to length(s) do begin
if not (s[i] in ['0'..'9']) then begin
if (i=1) and (s[i]='-') and (length(s)>1) then continue;
result:= False;
exit;
end
end
end;
function wwStrToFloat(const S: string): boolean;
var Buffer: array[0..63] of char;
Temp: Extended;
begin
result:= True;
if length(s)=0 then exit;
{$ifdef win32}
result:= TextToFloat(StrPLCopy(Buffer, S, Sizeof(Buffer)-1), Temp, fvExtended);
{$else}
result:= TextToFloat(StrPLCopy(Buffer, S, Sizeof(Buffer)-1), Temp);
{$endif}
end;
Function wwGetDateTimeCursorPosition(SelStart: integer; Text: string;
TimeOnly: Boolean): TwwDateTimeSelection;
var curPos, curitem: integer;
dateOrder: TwwDateOrder;
Date: TDateTime;
SecondPos: integer;
begin
curPos:= 1;
result:= wwdsDay; { makes compiler happy }
if (TimeOnly or (ScanDate(Text, CurPos, Date) and
((CurPos <= SelStart) or { SelStart is past date }
((curPos=selStart+1) and (Text[selStart]=' '))))) then
begin
curItem:= 0;
SecondPos:= 100;
repeat
if (strGetToken(Text, TimeSeparator, curpos)='') then break;
if (curpos=-1) or (curPos-1>selStart) then break;
if (curItem=1) then SecondPos:= curPos-1;
curPos:= curPos + 1;
inc(curItem);
until False;
case curItem of
0: result:= wwdsHour;
1: result:= wwdsMinute;
else result:= wwdsSecond;
end;
if (curItem=2) then
if (selStart>SecondPos+2) then
result:= wwdsAMPM;
exit;
end;
curPos:= 1;
curItem:= 0;
repeat
if (strGetToken(Text, DateSeparator, curpos)='') then break;
if (curpos=-1) or (curPos-1>selStart) then break;
inc(curItem);
until False;
DateOrder:= wwGetDateOrder(ShortDateFormat);
case curItem of
0: case DateOrder of
dodmy: result:= wwdsDay;
doymd: result:= wwdsYear;
domdy: result:= wwdsMonth;
end;
1: case DateOrder of
dodmy, doymd: result:= wwdsMonth;
domdy: result:= wwdsDay;
end;
2: case DateOrder of
dodmy, domdy: result:= wwdsYear;
doymd: result:= wwdsDay;
end;
end;
end;
Function wwGetTimeCursorPosition(SelStart: integer;
Text: string): TwwDateTimeSelection;
var curPos, curitem: integer;
SecondPos: integer;
begin
curPos:= 1;
result:= wwdsHour; { makes compiler happy }
if (CurPos <= SelStart) then
begin
curItem:= 0;
SecondPos:= 100;
repeat
if (strGetToken(Text, TimeSeparator, curpos)='') then break;
if (curpos=-1) or (curPos-1>selStart) then break;
if (curItem=1) then SecondPos:= curPos-1;
curPos:= curPos + 1;
inc(curItem);
until False;
case curItem of
0: result:= wwdsHour;
1: result:= wwdsMinute;
else result:= wwdsSecond;
end;
if (curItem=2) then
if (selStart>SecondPos+2) then
result:= wwdsAMPM;
exit;
end;
end;
Procedure wwSetDateTimeCursorSelection(
dateCursor: TwwDateTimeSelection; edit: TCustomEdit;
TimeOnly: Boolean);
var dateOrder: TwwDateOrder;
i, curpos, prevpos, matchNo: integer;
matchText: string;
Date: TDateTime;
spacePos: integer;
begin
if DateCursor in [wwdsDay, wwdsYear, wwdsMonth] then
begin
matchNo:= 0; {4/23/97 - Added to remove compiler warning}
DateOrder:= wwGetDateOrder(ShortDateFormat);
case DateCursor of
wwdsDay:
case DateOrder of
dodmy: matchNo:= 0;
doymd: matchNo:= 2;
domdy: matchNo:= 1;
end;
wwdsYear:
case DateOrder of
dodmy: matchNo:= 2;
doymd: matchNo:= 0;
domdy: matchNo:= 2;
end;
wwdsMonth:
case DateOrder of
dodmy: matchNo:= 1;
doymd: matchNo:= 1;
domdy: matchNo:= 0;
end;
else matchNo:= 0;
end;
curPos:= 1;
prevPos := 1;
for i:= 0 to MatchNo do
begin
prevPos:= curPos;
matchText:= strGetToken(Edit.Text, DateSeparator, curpos);
spacePos:= pos(' ', matchText);
if spacePos>0 then
matchText:= copy(matchText, 1, spacePos-1);
end;
Edit.selStart:= prevPos-1;
Edit.selLength:= length(MatchText);
end
else begin
CurPos:= 1;
prevpos:= 1;
if (timeonly or ScanDate(Edit.Text, CurPos, Date)) then
begin
case DateCursor of
wwdsHour: matchNo:= 0;
wwdsMinute : matchNo:= 1;
wwdsSecond : matchNo:= 2;
wwdsAMPM: matchNo:= 2;
else matchNo := 0;
end;
for i:= 0 to MatchNo do
begin
prevPos:= curPos;
matchText:= strGetToken(Edit.Text, TimeSeparator, curpos);
{ Don't include AM/PM }
if DateCursor=wwdsSecond then begin
spacePos:= pos(' ', matchText);
if spacePos>0 then
matchText:= copy(matchText, 1, spacePos-1);
end
else if DateCursor=wwdsAMPM then begin
spacePos:= pos(' ', matchText);
if spacePos>0 then
matchText:= copy(matchText, spacePos+1, 255);
prevPos:= prevPos + spacePos;
end
end
end;
Edit.selStart:= prevPos-1;
Edit.selLength:= length(MatchText);
end
end;
// 8/29/06 - Support E in editFormat so that it is not stripped if it is an exponential E
function wwStrToFloat2(const S: string; var FloatValue: Extended; DisplayFormat: string): boolean;
//var Buffer: array[0..63] of char;
// Temp: Extended;
var i, startpos: integer;
FloatString, TempText: string;
Negative: boolean;
ValidSet, ValidSet2: StrCharSet;
lastCharIsExponentialE: boolean;
function ExponentialE(pos: integer): boolean;
begin
result:= false;
if uppercase(s[pos])='E' then
begin
if (pos<length(s)) then
begin
if (s[pos+1] in [' ', '-', '+', '0'..'9']) then result:= true
end
end
end;
begin
result:= True;
FloatString:= '';
FloatValue:= 0; // 5/7/03 - In case of null string
if length(s)=0 then exit;
//StripLeading non digits
for i:= 1 to length(s) do
if s[i] in ['-', '0'..'9', DecimalSeparator, '('] then break;
startpos:= i;
Negative:= (s[i]='-');
//StripLeading non digits again if found negative.
if Negative then
begin
for i:= startpos to length(s) do
if s[i] in ['0'..'9', DecimalSeparator, '('] then break;
startpos:= i;
end;
lastCharIsExponentialE:= false;
//Remove commas and decimal point
for i:= startpos to length(s) do begin
ValidSet2:= ['0'..'9', DecimalSeparator];
if (lastCharIsExponentialE) then
ValidSet2:= ValidSet2 + ['+', '-'];
if (i>startpos) then
begin
ValidSet:= ['0'..'9', '(', ')', DecimalSeparator, ThousandSeparator];
if (lastCharIsExponentialE) then ValidSet:= ValidSet + ['+', '-'];
if length(CurrencyString)>0 then ValidSet:= ValidSet + [CurrencyString[1]];
lastCharIsExponentialE:= ExponentialE(i);
if not (s[i] in ValidSet) then
begin
if not ExponentialE(i) then continue; // 8/15/2001 - Keep scanning for other digits.
ValidSet2:= ValidSet2 + ['E', 'e'];
end
end;
if s[i]='(' then FloatString:= FloatString + '-';
if (s[i] in ValidSet2) then
FloatString:= FloatString + s[i];
end;
if Negative then FloatString:= '-' + FloatString;
result:= TextToFloat(pchar(FloatString), FloatValue, fvExtended);
if result and (FloatValue>0) and (DisplayFormat<>'') then begin
TempText:= FormatFloat(DisplayFormat, FloatValue);
if (TempText<>s) then
begin
TempText:= FormatFloat(DisplayFormat, -FloatValue);
if TempText=s then FloatValue:=-FloatValue;
end
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -