base_code.pas
来自「Delphi脚本控件」· PAS 代码 · 共 2,451 行 · 第 1/5 页
PAS
2,451 行
begin
Params[I] := ShiftPointer(P[I], 8);
if I < ParamCount then
begin
WS := Variant(P[I]^);
TWideChar(Params[I]^) := WS[1];
end;
end;
typeINTERFACE:
begin
Params[I] := @Integers[I];
if I < ParamCount then
begin
if IsObject(Variant(P[I]^)) then
begin
ScriptObject := VariantToScriptObject(Variant(P[I]^));
if ScriptObject.PIntf <> nil then
Move(ScriptObject.PIntf^, Integers[I], 4)
else
Move(ScriptObject.Intf, Integers[I], 4);
end
else
Integers[I] := 0;
end;
end;
typeCLASS:
begin
Params[I] := @Integers[I];
if I < ParamCount then
begin
if IsUndefined(Variant(P[I]^)) then
Integers[I] := 0 // nil
else
begin
tempSO := VariantToScriptObject(Variant(P[I]^));
if tempSO.ClassRec.ck = ckDynamicArray then
Integers[I] := Integer(tempSO.ExtraPtr)
else if tempSO.ClassRec.ck = ckStructure then
begin
Params[I] := tempSO.ExtraPtr;
Types[I] := typeRECORD;
if D.Consts[I] then
D.ByRefs[I] := true;
end
else if tempSO.ClassRec.ck = ckInterface then
begin
if tempSO.ClassRec.ClassID < 0 then
begin
TempClassDef := TPaxClassDefinition(DefinitionList[-tempSO.ClassRec.ClassID]);
Params[I] := @ TempClassDef.guid;
Types[I] := typeRECORD;
for J:=0 to ParamCount - 1 do
if D.Types[J] = typeINTERFACE then
if D.StrTypes[J] = '' then
StrTypes[J] := TempClassDef.Name;
end;
end
else
Integers[I] := Integer(tempSO.Instance);
end;
end
else
begin
Integers[I] := 0;
if D.ReturnsDynamicArray then
Types[ParamCount] := typeDYNAMICARRAY
else if D.Sizes[ParamCount] >= 0 then
begin
Types[ParamCount] := typeRECORD;
end;
end;
end;
typeCLASSREF:
begin
if I < ParamCount then
V := Variant(P[I]^);
Params[I] := @Integers[I];
if I < ParamCount then
begin
if IsUndefined(V) then
Integers[I] := 0 // nil
else
begin
// S := VariantToScriptObject(V).ClassRec.Name;
Integers[I] := Integer(VariantToScriptObject(V).ClassRec.fClassDef.PClass);
end;
end;
end;
typePCHAR:
Params[I] := ShiftPointer(P[I], 8);
typeSHORTSTRING:
begin
Params[I] := @ShortStrings[I];
if I < ParamCount then
ShortStrings[I] := Variant(P[I]^);
end;
typeWIDESTRING:
begin
if I < ParamCount then
V := Variant(P[I]^);
Params[I] := @WideStrings[I];
if I < ParamCount then
WideStrings[I] := V;
end;
typePWIDECHAR:
begin
if I < ParamCount then
V := Variant(P[I]^);
Params[I] := @WideStrings[I];
if I < ParamCount then
WideStrings[I] := V;
end;
typeSET:
begin
if I < ParamCount then
V := Variant(P[I]^);
Params[I] := @Integers[I];
if I < ParamCount then
begin
Integers[I] := 0;
if VarType(V) = varString then
begin
ClassRec := TPaxBaseScripter(Scripter).ClassList.FindClassByName(D.StrTypes[I]);
if ClassRec <> nil then
begin
ByteSet := StringToByteSet(ClassRec.PtiSet, V);
Move(ByteSet, Integers[I], SizeOf(TByteSet));
end;
end
else
begin
ByteSet := PaxArrayToByteSet(V);
Move(ByteSet, Integers[I], SizeOf(TByteSet));
end;
end;
end;
typeARRAY:
begin
// V := Variant(P[I]^);
// PaxArray := TPaxArray(VariantToScriptObject(V).Instance);
// Pointers[I] := PaxArray.LockArray;
// D.ExtraTypes[I] := typeARRAY;
// Types[I] := typePOINTER;
// Params[I] := @Pointers[I];
end;
typePOINTER:
begin
Params[I] := @Pointers[I];
if I < ParamCount then
begin
V := Variant(P[I]^);
if IsObject(V) then
begin
tempSO := VariantToScriptObject(V);
if tempSO.ClassRec.fClassDef <> nil then
Pointers[I] := tempSO.Instance
else
Pointers[I] := tempSO;
// Pointers[I] := tempSO.Instance;
end
else
Pointers[I] := Pointer(Integer(V));
end;
end;
end;
end;
Instance := nil;
AClass := nil;
if modSTATIC in D.ml then
AClass := D.PClass;
IsLock := false;
try
if D.Fake then
begin
if D.NewFake then
begin
Instance := SO.Instance;
__Scripter := TPAXBaseScripter(SO.Scripter).Owner;
S := Instance.ClassName;
end
else
begin
_BeginWrite;
IsLock := true;
__Self := SO.Instance;
__Scripter := TPAXBaseScripter(SO.Scripter).Owner;
end;
end
else if SO.ClassRec.GetClassDef <> nil then
begin
AClass := SO.ClassRec.GetClassDef.PClass;
if AClass = TPAXDelegate then
AClass := nil;
if not (modSTATIC in D.ml) then
Instance := SO.Instance;
if Instance <> nil then
AClass := nil;
end;
if D.DirectProc = @TObject.ClassName then
begin
Variant(P[ParamCount]^) := SO.ClassRec.Name;
Exit;
end
else if D.DirectProc = @TObject.ClassType then
begin
Variant(P[ParamCount]^) := SymbolTable.GetVariant(SO.ClassRec.ClassID);
Exit;
end
else if Instance <> nil then
if Instance.InheritsFrom(TStrings) then
if StrEql(D.Name, 'Clear') then
begin
(Instance as TStrings).Clear;
Exit;
end;
if D.TypeSub = tsDestructor then
begin
if SO.Instance <> nil then
begin
if Assigned(TPaxBaseScripter(Scripter).OnDelphiInstanceDestroy) then
TPaxBaseScripter(Scripter).OnDelphiInstanceDestroy(TPaxBaseScripter(Scripter).Owner, SO.Instance);
for I:=0 to TPaxBaseScripter(scripter).EventHandlerList.Count - 1 do
if TPAXEventHandler(TPaxBaseScripter(scripter).EventHandlerList[I]).DelphiInstance = SO.Instance then
TPAXEventHandler(TPaxBaseScripter(scripter).EventHandlerList[I]).DelphiInstance := nil;
SO.Instance.Free;
SO.Instance := nil;
W := TPAXBaseScripter(Scripter).ScriptObjectList;
W.RemoveObject(SO);
end;
VarClear(PThis^);
Exit;
end;
Address := D.DirectProc;
if D.IsIntf then
begin
if D.MethodIndex = 1 then
begin
IntVal := 0;
if SO.PIntf <> nil then
hr := SO.PIntf^.QueryInterface(PGUID(Params[0])^, IntVal)
else
hr := SO.Intf.QueryInterface(PGUID(Params[0])^, IntVal);
if hr <> E_NOINTERFACE then
begin
ScriptObject := InterfaceToScriptObject(IUnknown(IntVal), Scripter);
if ScriptObject = nil then
hr := E_NOINTERFACE
else
Variant(P[1]^) := ScriptObjectToVariant(ScriptObject);
end;
Variant(P[2]^) := hr;
Exit;
end
else if D.MethodIndex = 2 then
begin
if SO.PIntf <> nil then
SO.PIntf^._AddRef
else
SO.Intf._AddRef;
Exit;
end
else if D.MethodIndex = 3 then
begin
if SO.PIntf <> nil then
SO.PIntf^._Release
else
SO.Intf._Release;
Exit;
end;
if SO.PIntf <> nil then
begin
Move(SO.PIntf^, Instance, 4);
Address := GetMethodAddress(Pointer(SO.PIntf^), D.MethodIndex);
end
else
begin
Move(SO.Intf, Instance, 4);
Address := GetMethodAddress(Pointer(SO.Intf), D.MethodIndex);
end;
end;
BASE_CALL.Call(Address,
AClass,
Instance,
(D.TypeSub = tsConstructor) and (not D.Fake),
D.CallConv,
Params,
Types,
D.ExtraTypes,
D.ByRefs,
D.Sizes,
D.IsIntf);
finally
if IsLock then
_EndWrite;
end;
if PResult = nil then
Dec(ParamCount);
for I:=0 to ParamCount do
if D.ExtraTypes[I] = typeDYNAMICARRAY then
begin
if D.ByRefs[I] then
Variant(P[I]^) := DynamicArrayToVariant(Scripter, Pointers[I], D.StrTypes[I], D.Types[I]);
EraseDynamicArray(Scripter, Pointers[I], D.Types[I]);
end
else
if D.ExtraTypes[I] = typeARRAY then
begin
// V := Variant(P[I]^);
// PaxArray := TPaxArray(VariantToScriptObject(V).Instance);
// PaxArray.UnLockArray(true);
end;
for I:=0 to ParamCount do
if not (D.ExtraTypes[I] in [typeDYNAMICARRAY, typeARRAY]) then
begin
T := Types[I];
if D.ByRefs[I] then
begin
case T of
typeVARIANT:
begin
VT := VarType(Variant(Params[I]^));
if VT = varUnknown then
begin
Move(TVarData(Params[I]^).VUnknown, IntVal, 4);
ScriptObject := TPaxBaseScripter(Scripter).ScriptObjectList.FindScriptObjectByIntf(PUnknown(@IntVal));
if ScriptObject = nil then
begin
ScriptObject := InterfaceToScriptObject(IUnknown(IntVal), scripter);
// ScriptObject.Intf := IUnknown(Integers[I]);
// Move(Integers[I], ScriptObject.Intf, 4);
ScriptObject.RefCount := 1;
end;
Variant(P[I]^) := ScriptObjectToVariant(ScriptObject);
end
else
Variant(P[I]^) := Variants[I];
continue;
end;
typeOLEVARIANT:
begin
continue;
end;
typeSTRING:
begin
Variant(P[I]^) := Strings[I];
Strings[I] := '';
end;
typeINTEGER,
typeBYTE,
typeWORD,
typeENUM: TVarData(Variant(P[I]^)).VType := varInteger;
typeSET:
begin
ByteSet := [];
Move(Integers[I], ByteSet, SizeOf(ByteSet));
Variant(P[I]^) := ByteSetToPaxArray(ByteSet, Scripter);
end;
typeDOUBLE:
begin
Variant(P[I]^) := Doubles[I];
end;
typeSINGLE:
begin
Dbl := Singles[I];
Variant(P[I]^) := Dbl;
end;
typeCURRENCY:
begin
Dbl := Currences[I];
Variant(P[I]^) := Dbl;
end;
typeCOMP:
begin
Dbl := Comps[I];
Variant(P[I]^) := Dbl;
end;
typeSMALLINT:
begin
Integer(Params[I]^) := SmallInt(Params[I]^);
TVarData(Variant(P[I]^)).VType := varInteger;
end;
typeSHORTINT:
begin
Integer(Params[I]^) := ShortInt(Params[I]^);
TVarData(Variant(P[I]^)).VType := varInteger;
end;
typeREAL48:
begin
Dbl := Reals[I];
Variant(P[I]^) := Dbl;
end;
typeEXTENDED:
begin
Dbl := Extendeds[I];
Variant(P[I]^) := Dbl;
end;
typeWORDBOOL:
Variant(P[I]^) := WordBool(Params[I]^);
typeLONGBOOL:
Variant(P[I]^) := LongBool(Params[I]^);
typeBOOLEAN:
begin
TVarData(Variant(P[I]^)).VType := varBoolean;
if Byte(Params[I]^) <> 0 then
ShortInt(Params[I]^) := -1;
end;
typeCHAR:
begin
S := TChar(Params[I]^);
Variant(P[I]^) := S;
end;
typeWIDECHAR:
begin
WS := TWideChar(Params[I]^);
Variant(P[I]^) := WS;
end;
typeWIDESTRING:
begin
Variant(P[I]^) := WideStrings[I];
end;
typeRECORD:
begin
if I = ParamCount then
begin
ClassRec := TPaxBaseScripter(Scripter).ClassList.FindClassByName(D.ResultType);
tempSO := ClassRec.CreateScriptObject;
Move(Integers[I], tempSO.ExtraPtr^, D.Sizes[I]);
Variant(P[I]^) := ScriptObjectToVariant(tempSO);
end;
end;
typeDYNAMICARRAY:
if I = ParamCount then
begin
if Integers[I] = 0 then
begin
// Variant(P[I]^) := Undefined;
ClassRec := TPaxBaseScripter(Scripter).ClassList.FindClassByName(D.ResultType);
tempSO := ClassRec.CreateScriptObject;
tempSO.Instance := tempSO;
PP := AllocMem(8);
tempSO.ExtraPtr := ShiftPointer(PP, 8);
tempSO.ExternalExtraPtr := false;
tempSO.ExtraPtrSize := - 8;
PP := ShiftPointer(tempSO.ExtraPtr, -8);
Inc(Integer(PP^));
Variant(P[I]^) := ScriptObjectToVariant(tempSO);
end
else
begin
ClassRec := TPaxBaseScripter(Scripter).ClassList.FindClassByName(D.ResultType);
tempSO := ClassRec.CreateScriptObject;
tempSO.Instance := tempSO;
tempSO.ExtraPtr := Pointer(Integers[I]);
tempSO.ExternalExtraPtr := true;
PP := ShiftPointer(tempSO.ExtraPtr, -8);
Inc(Integer(PP^));
Variant(P[I]^) := ScriptObjectToVariant(tempSO);
end;
end;
t
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?