📄 myldbd4routines.pas
字号:
{ EDX Pointer to Indices }
{ ECX High bound of Indices }
{ [EBP+8] Pointer to result }
PUSH EBX
MOV EBX,ECX
INC EBX
JLE @@endLoop
@@loop:
PUSH [EDX+ECX*4].Integer
DEC ECX
JNS @@loop
@@endLoop:
PUSH EBX
PUSH EAX
MOV EAX,[EBP+8]
PUSH EAX
CALL MYLDB_VarArrayGet
LEA ESP,[ESP+EBX*4+3*4]
POP EBX
end; //VarArrayGet
procedure GetMemoryManager(var MemMgr: TMemoryManager);
begin
MemMgr := MemoryManager;
end;
procedure SetMemoryManager(const MemMgr: TMemoryManager);
begin
MemoryManager := MemMgr;
end;
function IsMemoryManagerSet: Boolean;
begin
with MemoryManager do
Result := (@GetMem <> @SysGetMem) or (@FreeMem <> @SysFreeMem) or
(@ReallocMem <> @SysReallocMem);
end;
(*
function StrToFloat(const S: string): Extended;
begin
if not TextToFloat(PChar(S), Result, fvExtended) then
raise EMYLDBException.Create(10441,ErrorLInvalidFloat,[S]);
end;
function StrToFloat(const S: string;
const FormatSettings: TFormatSettings): Extended;
begin
if not TextToFloat(PChar(S), Result, fvExtended, FormatSettings) then
raise EMYLDBException.Create(10442,ErrorLInvalidFloat,[S]);
end;
function StrToFloatDef(const S: string; const Default: Extended): Extended;
begin
if not TextToFloat(PChar(S), Result, fvExtended) then
Result := Default;
end;
function StrToFloatDef(const S: string; const Default: Extended;
const FormatSettings: TFormatSettings): Extended;
begin
if not TextToFloat(PChar(S), Result, fvExtended, FormatSettings) then
Result := Default;
end;
function FloatToStr(Value: Extended): string;
var
Buffer: array[0..63] of Char;
begin
SetString(Result, Buffer, FloatToText(Buffer, Value, fvExtended,
ffGeneral, 15, 0));
end;
function FloatToStr(Value: Extended;
const FormatSettings: TFormatSettings): string;
var
Buffer: array[0..63] of Char;
begin
SetString(Result, Buffer, FloatToText(Buffer, Value, fvExtended,
ffGeneral, 15, 0, FormatSettings));
end;
*)
function TryFloatToCurr(const Value: Extended; out AResult: Currency): Boolean;
begin
Result := (Value >= MinCurrency) and (Value <= MaxCurrency);
if Result then
AResult := Value;
end;
function FloatToCurr(const Value: Extended): Currency;
begin
if not TryFloatToCurr(Value, Result) then
raise EMYLDBException.Create(10439,ErrorLInvalidCurrency,[FloatToStr(Value)]);
end;
procedure VerifyBoolStrArray;
begin
if Length(TrueBoolStrs) = 0 then
begin
SetLength(TrueBoolStrs, 1);
TrueBoolStrs[0] := DefaultTrueBoolStr;
end;
if Length(FalseBoolStrs) = 0 then
begin
SetLength(FalseBoolStrs, 1);
FalseBoolStrs[0] := DefaultFalseBoolStr;
end;
end;
function StrToBool(const S: string): Boolean;
begin
if not TryStrToBool(S, Result) then
raise EMYLDBException.Create(10440,ErrorLInvalidBoolean,[s]);
end;
function StrToBoolDef(const S: string; const Default: Boolean): Boolean;
begin
if not TryStrToBool(S, Result) then
Result := Default;
end;
function TryStrToBool(const S: string; out Value: Boolean): Boolean;
function CompareWith(const aArray: array of string): Boolean;
var
I: Integer;
begin
Result := False;
for I := Low(aArray) to High(aArray) do
if AnsiSameText(S, aArray[I]) then
begin
Result := True;
Break;
end;
end;
var
LResult: Extended;
begin
Result := TryStrToFloat(S, LResult);
if Result then
Value := LResult <> 0
else
begin
VerifyBoolStrArray;
Result := CompareWith(TrueBoolStrs);
if Result then
Value := True
else
begin
Result := CompareWith(FalseBoolStrs);
if Result then
Value := False;
end;
end;
end;
function BoolToStr(B: Boolean; UseBoolStrs: Boolean = False): string;
const
cSimpleBoolStrs: array [boolean] of String = ('0', '-1');
begin
if UseBoolStrs then
begin
VerifyBoolStrArray;
if B then
Result := TrueBoolStrs[0]
else
Result := FalseBoolStrs[0];
end
else
Result := cSimpleBoolStrs[B];
end;
function TryStrToFloat(const S: string; out Value: Extended): Boolean;
begin
Result := TextToFloat(PChar(S), Value, fvExtended);
end;
function TryStrToFloat(const S: string; out Value: Double): Boolean;
var
LValue: Extended;
begin
Result := TextToFloat(PChar(S), LValue, fvExtended);
if Result then
Value := LValue;
end;
function TryStrToFloat(const S: string; out Value: Single): Boolean;
var
LValue: Extended;
begin
Result := TextToFloat(PChar(S), LValue, fvExtended);
if Result then
Value := LValue;
end;
{$IFNDEF D5H}
{ AnsiSameText compares S1 to S2, without case-sensitivity. The compare
operation is controlled by the current Windows locale. The return value
is True if AnsiCompareText would have returned 0. }
function AnsiSameText(const S1, S2: string): Boolean;
begin
Result := CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, PChar(S1),
Length(S1), PChar(S2), Length(S2)) = 2;
end;
{$ENDIF}
{$IFNDEF D5H}
{ TMasterDataLink }
constructor TMasterDataLink.Create(DataSet: TDataSet);
begin
inherited Create;
FDataSet := DataSet;
FFields := TList.Create;
end;
destructor TMasterDataLink.Destroy;
begin
FFields.Free;
inherited Destroy;
end;
procedure TMasterDataLink.ActiveChanged;
begin
FFields.Clear;
if Active then
try
DataSet.GetFieldList(FFields, FFieldNames);
except
FFields.Clear;
raise;
end;
if FDataSet.Active and not (csDestroying in FDataSet.ComponentState) then
if Active and (FFields.Count > 0) then
begin
if Assigned(FOnMasterChange) then FOnMasterChange(Self);
end else
if Assigned(FOnMasterDisable) then FOnMasterDisable(Self);
end;
procedure TMasterDataLink.CheckBrowseMode;
begin
if FDataSet.Active then FDataSet.CheckBrowseMode;
end;
function TMasterDataLink.GetDetailDataSet: TDataSet;
begin
Result := FDataSet;
end;
procedure TMasterDataLink.LayoutChanged;
begin
ActiveChanged;
end;
procedure TMasterDataLink.RecordChanged(Field: TField);
begin
if (DataSource.State <> dsSetKey) and FDataSet.Active and
(FFields.Count > 0) and ((Field = nil) or
(FFields.IndexOf(Field) >= 0)) and
Assigned(FOnMasterChange) then
FOnMasterChange(Self);
end;
procedure TMasterDataLink.SetFieldNames(const Value: string);
begin
if FFieldNames <> Value then
begin
FFieldNames := Value;
ActiveChanged;
end;
end;
{$ENDIF}
procedure FreeAndNil(var Obj);
var
Temp: TObject;
begin
Temp := TObject(Obj);
Pointer(Obj) := nil;
Temp.Free;
end;
function Sign(const AValue: Integer): TValueSign;
begin
Result := ZeroValue;
if AValue < 0 then
Result := NegativeValue
else if AValue > 0 then
Result := PositiveValue;
end;
function Sign(const AValue: Int64): TValueSign;
begin
Result := ZeroValue;
if AValue < 0 then
Result := NegativeValue
else if AValue > 0 then
Result := PositiveValue;
end;
function Sign(const AValue: Double): TValueSign;
begin
if ((PInt64(@AValue)^ and $7FFFFFFFFFFFFFFF) = $0000000000000000) then
Result := ZeroValue
else if ((PInt64(@AValue)^ and $8000000000000000) = $8000000000000000) then
Result := NegativeValue
else
Result := PositiveValue;
end;
function EncodeDateTime(const AYear, AMonth, ADay, AHour, AMinute, ASecond,
AMilliSecond: Word): TDateTime;
begin
if not TryEncodeDateTime(AYear, AMonth, ADay,
AHour, AMinute, ASecond, AMilliSecond, Result) then
InvalidDateTimeError(AYear, AMonth, ADay,
AHour, AMinute, ASecond, AMilliSecond);
end;
function TryEncodeDateTime(const AYear, AMonth, ADay, AHour, AMinute, ASecond,
AMilliSecond: Word; out AValue: TDateTime): Boolean;
var
LTime: TDateTime;
begin
Result := TryEncodeDate(AYear, AMonth, ADay, AValue);
if Result then
begin
Result := TryEncodeTime(AHour, AMinute, ASecond, AMilliSecond, LTime);
if Result then
AValue := AValue + LTime;
end;
end;
function TryEncodeDate(Year, Month, Day: Word; out Date: TDateTime): Boolean;
var
I: Integer;
DayTable: PDayTable;
begin
Result := False;
DayTable := @MonthDays[IsLeapYear(Year)];
if (Year >= 1) and (Year <= 9999) and (Month >= 1) and (Month <= 12) and
(Day >= 1) and (Day <= DayTable^[Month]) then
begin
for I := 1 to Month - 1 do Inc(Day, DayTable^[I]);
I := Year - 1;
Date := I * 365 + I div 4 - I div 100 + I div 400 + Day - DateDelta;
Result := True;
end;
end;
function TryEncodeTime(Hour, Min, Sec, MSec: Word; out Time: TDateTime): Boolean;
begin
Result := False;
if (Hour < HoursPerDay) and (Min < MinsPerHour) and (Sec < SecsPerMin) and (MSec < MSecsPerSec) then
begin
Time := (Hour * (MinsPerHour * SecsPerMin * MSecsPerSec) +
Min * (SecsPerMin * MSecsPerSec) +
Sec * MSecsPerSec +
MSec) / MSecsPerDay;
Result := True;
end;
end;
procedure InvalidDateTimeError(const AYear, AMonth, ADay, AHour, AMinute,
ASecond, AMilliSecond: Word; const ABaseDate: TDateTime);
function Translate(AOrig, AValue: Word): string;
begin
if AValue = RecodeLeaveFieldAsIs then
if ABaseDate = 0 then
Result := SMissingDateTimeField
else
Result := IntToStr(AOrig)
else
Result := IntToStr(AValue);
end;
var
LYear, LMonth, LDay, LHour, LMinute, LSecond, LMilliSecond: Word;
begin
DecodeDate(ABaseDate, LYear, LMonth, LDay);
DecodeTime(ABaseDate, LHour, LMinute, LSecond, LMilliSecond);
raise EConvertError.CreateFmt(SInvalidDateTime,
[Translate(LYear, AYear) + DateSeparator +
Translate(LMonth, AMonth) + DateSeparator +
Translate(LDay, ADay) + ' ' +
Translate(LHour, AHour) + TimeSeparator +
Translate(LMinute, AMinute) + TimeSeparator +
Translate(LSecond, ASecond) + DecimalSeparator +
Translate(LMilliSecond, AMilliSecond)]);
end;
initialization
ClearAnyProc := @VarInvalidOp;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -