📄 cxoi.pas
字号:
begin
for I := 0 to List.Count - 1 do
TObject(List[I]).Free;
List.Free;
List := nil;
end;
end;
{ TcxPropertyEditor }
constructor TcxPropertyEditor.Create(AOwner: TComponent;
AInspector: TcxCustomRTTIInspector; APropCount: Integer);
begin
GetMem(FPropList, APropCount * SizeOf(TcxInstProp));
FInspector := AInspector;
FPropCount := APropCount;
FOwner := AOwner;
end;
destructor TcxPropertyEditor.Destroy;
begin
if FPropList <> nil then
FreeMem(FPropList, FPropCount * SizeOf(TcxInstProp));
inherited Destroy;
end;
function TcxPropertyEditor.AllEqual: Boolean;
begin
Result := FPropCount = 1;
end;
procedure TcxPropertyEditor.Edit;
type
TcxGetStrFunc = function(const Value: string): Integer of object;
var
I: Integer;
Values: TStringList;
AddValue: TcxGetStrFunc;
begin
Values := TStringList.Create;
Values.Sorted := ipaSortList in GetAttributes;
try
AddValue := Values.Add;
GetValues(TGetStrProc(AddValue));
if Values.Count > 0 then
begin
I := Values.IndexOf(Value) + 1;
if I = Values.Count then I := 0;
Value := Values[I];
end;
finally
Values.Free;
end;
end;
function TcxPropertyEditor.GetAttributes: TcxPropertyAttributes;
begin
Result := [ipaMultiSelect, ipaRevertable];
end;
function TcxPropertyEditor.GetComponent(Index: Integer): TPersistent;
begin
Result := FPropList^[Index].Instance;
end;
function TcxPropertyEditor.GetFloatValue: Extended;
begin
Result := GetFloatValueAt(0);
end;
function TcxPropertyEditor.GetFloatValueAt(Index: Integer): Extended;
begin
with FPropList^[Index] do
Result := GetFloatProp(Instance, PropInfo);
end;
function TcxPropertyEditor.GetInt64Value: Int64;
begin
Result := GetInt64ValueAt(0);
end;
function TcxPropertyEditor.GetInt64ValueAt(Index: Integer): Int64;
begin
with FPropList^[Index] do
Result := GetInt64Prop(Instance, PropInfo);
end;
function TcxPropertyEditor.GetEditLimit: Integer;
begin
Result := 255;
end;
function TcxPropertyEditor.GetName: string;
begin
Result := FPropList^[0].PropInfo^.Name;
end;
function TcxPropertyEditor.GetOrdValue: Longint;
begin
Result := GetOrdValueAt(0);
end;
function TcxPropertyEditor.GetOrdValueAt(Index: Integer): Longint;
begin
with FPropList^[Index] do
Result := GetOrdProp(Instance, PropInfo);
end;
procedure TcxPropertyEditor.GetProperties(AOwner: TComponent; Proc: TcxGetPropEditProc);
begin
end;
procedure TcxPropertyEditor.AdjustInnerEditProperties(
AProperties: TcxCustomEditProperties);
begin
end;
function TcxPropertyEditor.GetPropInfo: PPropInfo;
begin
Result := FPropList^[0].PropInfo;
end;
function TcxPropertyEditor.GetPropType: PTypeInfo;
begin
Result := FPropList^[0].PropInfo^.PropType^;
end;
function TcxPropertyEditor.GetStrValue: string;
begin
Result := GetStrValueAt(0);
end;
function TcxPropertyEditor.GetStrValueAt(Index: Integer): string;
begin
with FPropList^[Index] do
Result := GetStrProp(Instance, PropInfo);
end;
function TcxPropertyEditor.GetVarValue: Variant;
begin
Result := GetVarValueAt(0);
end;
function TcxPropertyEditor.GetVarValueAt(Index: Integer): Variant;
begin
with FPropList^[Index] do
Result := GetVariantProp(Instance, PropInfo);
end;
function TcxPropertyEditor.GetValue: string;
begin
Result := srUnknown;
end;
procedure TcxPropertyEditor.GetValues(Proc: TGetStrProc);
begin
end;
function TcxPropertyEditor.FindRoot: TComponent;
begin
Result := FOwner;
end;
procedure TcxPropertyEditor.PostChangedNotification;
begin
Inspector.PostChangedNotification;
end;
procedure TcxPropertyEditor.SetFloatValue(Value: Extended);
var
I: Integer;
begin
for I := 0 to FPropCount - 1 do
with FPropList^[I] do
SetFloatProp(Instance, PropInfo, Value);
end;
procedure TcxPropertyEditor.SetInt64Value(Value: Int64);
var
I: Integer;
begin
for I := 0 to FPropCount - 1 do
with FPropList^[I] do
SetInt64Prop(Instance, PropInfo, Value);
end;
procedure TcxPropertyEditor.SetOrdValue(Value: Longint);
var
I: Integer;
begin
for I := 0 to FPropCount - 1 do
with FPropList^[I] do
SetOrdProp(Instance, PropInfo, Value);
end;
procedure TcxPropertyEditor.SetStrValue(const Value: string);
var
I: Integer;
begin
for I := 0 to FPropCount - 1 do
with FPropList^[I] do
SetStrProp(Instance, PropInfo, Value);
end;
procedure TcxPropertyEditor.SetVarValue(const Value: Variant);
var
I: Integer;
begin
for I := 0 to FPropCount - 1 do
with FPropList^[I] do
SetVariantProp(Instance, PropInfo, Value);
end;
procedure TcxPropertyEditor.SetValue(const Value: string);
begin
end;
function AncestorIsValid(Ancestor: TPersistent; Root, RootAncestor: TComponent): Boolean;
begin
Result := (Ancestor <> nil) and (RootAncestor <> nil) and
Root.InheritsFrom(RootAncestor.ClassType);
end;
{$IFNDEF DELPHI6}
type
IInterfaceComponentReference = interface
['{E28B1858-EC86-4559-8FCD-6B4F824151ED}']
function GetComponent: TComponent;
end;
function VarSameValue(const A, B: Variant): Boolean;
var
LA, LB: TVarData;
begin
LA := FindVarData(A)^;
LB := FindVarData(B)^;
if LA.VType = varEmpty then
Result := LB.VType = varEmpty
else if LA.VType = varNull then
Result := LB.VType = varNull
else if LB.VType in [varEmpty, varNull] then
Result := False
else
Result := A = B;
end;
function VarIsClear(const V: Variant): Boolean;
var
LVarData: TVarData;
begin
LVarData := FindVarData(V)^;
with LVarData do
Result := (VType = varEmpty) or
(((VType = varDispatch) or (VType = varUnknown)) and (VDispatch = nil));
end;
function GetInterfaceProp(Instance: TObject; PropInfo: PPropInfo): IInterface;
type
TInterfaceGetProc = function :IInterface of object;
TInterfaceIndexedGetProc = function (Index: Integer): IInterface of object;
var
P: ^IInterface;
M: TMethod;
Getter: Longint;
begin
Getter := Longint(PropInfo^.GetProc);
if (Getter and $FF000000) = $FF000000 then
begin // field - Getter is the field's offset in the instance data
P := Pointer(Integer(Instance) + (Getter and $00FFFFFF));
Result := P^; // auto ref count
end
else
begin
if (Getter and $FF000000) = $FE000000 then
// virtual method - Getter is a signed 2 byte integer VMT offset
M.Code := Pointer(PInteger(PInteger(Instance)^ + SmallInt(Getter))^)
else
// static method - Getter is the actual address
M.Code := Pointer(Getter);
M.Data := Instance;
if PropInfo^.Index = Integer($80000000) then // no index
Result := TInterfaceGetProc(M)()
else
Result := TInterfaceIndexedGetProc(M)(PropInfo^.Index);
end;
end;
function GetObjectProp(Instance: TObject; PropInfo: PPropInfo): TObject;
begin
Result := TObject(GetOrdProp(Instance, PropInfo));
end;
function GetWideStrProp(Instance: TObject; PropInfo: PPropInfo): WideString;
type
TWideStringGetProc = function :WideString of object;
TWideStringIndexedGetProc = function (Index: Integer): WideString of object;
var
P: PWideString;
M: TMethod;
Getter: Longint;
begin
case PropInfo^.PropType^.Kind of
tkString,
tkLString: Result := GetStrProp(Instance, PropInfo);
tkWString:
begin
Getter := Longint(PropInfo^.GetProc);
if (Getter and $FF000000) = $FF000000 then
begin // field - Getter is the field's offset in the instance data
P := Pointer(Integer(Instance) + (Getter and $00FFFFFF));
Result := P^; // auto ref count
end
else
begin
if (Getter and $FF000000) = $FE000000 then
// virtual method - Getter is a signed 2 byte integer VMT offset
M.Code := Pointer(PInteger(PInteger(Instance)^ + SmallInt(Getter))^)
else
// static method - Getter is the actual address
M.Code := Pointer(Getter);
M.Data := Instance;
if PropInfo^.Index = Integer($80000000) then // no index
Result := TWideStringGetProc(M)()
else
Result := TWideStringIndexedGetProc(M)(PropInfo^.Index);
end;
end;
else
Result := '';
end;
end;
{$ENDIF}
{$IFNDEF DELPHI7}
type
TGetLookupInfoEvent = procedure(var Ancestor: TPersistent;
var Root, LookupRoot, RootAncestor: TComponent) of object;
function IsDefaultPropertyValue(Instance: TObject; PropInfo: PPropInfo;
OnGetLookupInfo: TGetLookupInfoEvent): Boolean;
var
PropType: PTypeInfo;
Ancestor: TPersistent;
LookupRoot: TComponent;
RootAncestor: TComponent;
Root: TComponent;
AncestorValid: Boolean;
function IsDefaultOrdProp: Boolean;
var
Value: Longint;
Default: LongInt;
begin
Value := GetOrdProp(Instance, PropInfo);
if AncestorValid then
Result := Value = GetOrdProp(Ancestor, PropInfo)
else
begin
Default := PPropInfo(PropInfo)^.Default;
Result := (Default <> LongInt($80000000)) and (Value = Default);
end;
end;
function IsDefaultFloatProp: Boolean;
var
Value: Extended;
begin
Value := GetFloatProp(Instance, PropInfo);
if AncestorValid then
Result := Value = GetFloatProp(Ancestor, PropInfo)
else
Result := Value = 0;;
end;
function IsDefaultInt64Prop: Boolean;
var
Value: Int64;
begin
Value := GetInt64Prop(Instance, PropInfo);
if AncestorValid then
Result := Value = GetInt64Prop(Ancestor, PropInfo)
else
Result := Value = 0;
end;
function IsDefaultStrProp: Boolean;
var
Value: WideString;
begin
Value := GetWideStrProp(Instance, PropInfo);
if AncestorValid then
Result := Value = GetWideStrProp(Ancestor, PropInfo)
else
Result := Value = '';
end;
function ObjectAncestorMatch(AncestorValue, Value: TComponent): Boolean;
begin
Result := (AncestorValue <> nil) and (AncestorValue.Owner = RootAncestor) and
(Value <> nil) and (Value.Owner = Root) and
SameText(AncestorValue.Name, Value.Name);
end;
function IsDefaultObjectProp: Boolean;
var
Value: TObject;
function IsDefault: Boolean;
var
AncestorValue: TObject;
begin
AncestorValue := nil;
if AncestorValid then
begin
AncestorValue := TObject(GetOrdProp(Ancestor, PropInfo));
if ObjectAncestorMatch(TComponent(AncestorValue), TComponent(Value)) then
AncestorValue := Value;
end;
Result := Value = AncestorValue;
end;
begin
Result := True;
Value := TObject(GetOrdProp(Instance, PropInfo));
if (Value = nil) and not IsDefault then
begin
Result := False; // nil wasn't the "default" value
end
else if Value is TPersistent then
begin
{$IFDEF DELPHI6}
if (Value is TComponent) and
not (csSubComponent in TComponent(Value).ComponentStyle) then
begin
if not IsDefault then
begin
// A non sub-component TComponent is only non-default if
// it actually has a name (that way, it can be streamed out -
// it can't be streamed without a name).
if TComponent(Value).Name <> '' then
Result := False;
end
end
else
{$ENDIF}
Result := False; // The TPersistent should be checked for default's by the caller
end;
end;
function IsDefaultInterfaceProp: Boolean;
var
Intf: IInterface;
Value: TComponent;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -