ideintf: TRecordPropertyEditor: use all registered editors

This commit is contained in:
mattias 2024-09-02 16:33:17 +02:00
parent 700bf810cc
commit 32baef49e0

View File

@ -1366,7 +1366,8 @@ procedure GetPersistentProperties(AItem: TPersistent;
AFilter: TTypeKinds; AHook: TPropertyEditorHook; AProc: TGetPropEditProc; AFilter: TTypeKinds; AHook: TPropertyEditorHook; AProc: TGetPropEditProc;
AEditorFilterFunc: TPropertyEditorFilterFunc); AEditorFilterFunc: TPropertyEditorFilterFunc);
function GetEditorClass(PropInfo:PPropInfo; Obj: TPersistent): TPropertyEditorClass; function GetEditorClass(PropInfo: PPropInfo; Obj: TPersistent): TPropertyEditorClass;
function GetEditorClass(PropName: shortstring; Info: PTypeInfo; Obj: TPersistent): TPropertyEditorClass;
//============================================================================== //==============================================================================
@ -2147,7 +2148,6 @@ end;
constructor TRecordPropertyEditor.Create(Hook: TPropertyEditorHook; APropCount: Integer); constructor TRecordPropertyEditor.Create(Hook: TPropertyEditorHook; APropCount: Integer);
begin begin
inherited Create(Hook, APropCount); inherited Create(Hook, APropCount);
writeln('TRecordPropertyEditor.Create ');
end; end;
destructor TRecordPropertyEditor.Destroy; destructor TRecordPropertyEditor.Destroy;
@ -2179,16 +2179,15 @@ var
Instance: TPersistent; Instance: TPersistent;
FieldList: PExtendedFieldInfoTable; FieldList: PExtendedFieldInfoTable;
Field: PExtendedVmtFieldEntry; Field: PExtendedVmtFieldEntry;
EdClass: TPropertyEditorClass;
{$ENDIF} {$ENDIF}
begin begin
writeln('TRecordPropertyEditor.GetProperties START');
{$IFDEF HasExtRtti} {$IFDEF HasExtRtti}
Instance:=FPropList^[0].Instance; Instance:=FPropList^[0].Instance;
PropInfo:=GetPropInfo; PropInfo:=GetPropInfo;
if PropInfo=nil then if PropInfo=nil then
exit; exit;
writeln('TRecordPropertyEditor.GetProperties aPropInfo^.Name=',GetPropInfo^.Name);
aTypeData:=GetTypeData(PropInfo^.PropType); aTypeData:=GetTypeData(PropInfo^.PropType);
FieldCnt:=GetFieldList(PropInfo^.PropType,FieldList,[vcPublic,vcPublished]); FieldCnt:=GetFieldList(PropInfo^.PropType,FieldList,[vcPublic,vcPublished]);
@ -2209,19 +2208,17 @@ begin
Field:=FieldList^[i]; Field:=FieldList^[i];
FieldTypeInfo:=Field^.FieldType^; FieldTypeInfo:=Field^.FieldType^;
// todo filter editors EdClass:=GetEditorClass('',FieldTypeInfo,nil);
Editor := EdClass.Create(PropertyHook,1);
case FieldTypeInfo^.Kind of Editor.SetRecordFieldEntry(0, PByte(FRecordData)+Field^.FieldOffset, Field^.Name, FieldTypeInfo);
tkInteger: Editor.Initialize;
begin
Editor:=TIntegerPropertyEditor.Create(PropertyHook,1);
Editor.SetRecordFieldEntry(0, PByte(FRecordData)+Field^.FieldOffset, Field^.Name, FieldTypeInfo);
Editor.Initialize;
Proc(Editor);
end;
else
if ((PropCount > 1) and not (paMultiSelect in Editor.GetAttributes))
or not Editor.ValueAvailable
then begin
Editor.Free;
end else begin
Proc(Editor);
end; end;
end; end;
end; end;
@ -2242,7 +2239,6 @@ end;
procedure TRecordPropertyEditor.Initialize; procedure TRecordPropertyEditor.Initialize;
var var
PropInfo: PPropInfo; PropInfo: PPropInfo;
aTypeData: PTypeData;
begin begin
inherited Initialize; inherited Initialize;
@ -2250,9 +2246,6 @@ begin
if PropInfo=nil then if PropInfo=nil then
exit; exit;
writeln('TRecordPropertyEditor.Initialize aPropInfo^.Name=',GetPropInfo^.Name);
aTypeData:=GetTypeData(PropInfo^.PropType);
// check read and write access // check read and write access
FReadAccess:=(PropInfo^.PropProcs) and 3; FReadAccess:=(PropInfo^.PropProcs) and 3;
FCanReadFields:=FReadAccess in [ptField{,ptStatic,ptVirtual}]; FCanReadFields:=FReadAccess in [ptField{,ptStatic,ptVirtual}];
@ -2811,9 +2804,7 @@ end;
function GetEditorClass(PropInfo:PPropInfo; Obj:TPersistent): TPropertyEditorClass; function GetEditorClass(PropInfo:PPropInfo; Obj:TPersistent): TPropertyEditorClass;
var var
PropType:PTypeInfo; I: Integer;
P,C:PPropertyClassRec;
I:Integer;
begin begin
Result := nil; Result := nil;
if PropertyEditorMapperList<>nil then begin if PropertyEditorMapperList<>nil then begin
@ -2824,56 +2815,65 @@ begin
end; end;
end; end;
end; end;
if Result=nil then begin Result:=GetEditorClass(PropInfo^.Name,PropInfo^.PropType,Obj);
PropType:=PropInfo^.PropType; end;
I:=0;
C:=nil;
while I < PropertyClassList.Count do begin
P:=PropertyClassList[I];
if ((P^.PropertyType=PropType) or function GetEditorClass(PropName: shortstring; Info: PTypeInfo; Obj: TPersistent
((P^.PropertyType^.Kind=PropType^.Kind) and ): TPropertyEditorClass;
(P^.PropertyType^.Name=PropType^.Name) var
) P, C: PPropertyClassRec;
) or I: Integer;
( (PropType^.Kind=tkClass) and TypeData: PTypeData;
(P^.PropertyType^.Kind=tkClass) and begin
GetTypeData(PropType)^.ClassType.InheritsFrom( Result := nil;
GetTypeData(P^.PropertyType)^.ClassType) I:=0;
C:=nil;
TypeData:=GetTypeData(Info);
while I < PropertyClassList.Count do begin
P:=PropertyClassList[I];
if ((P^.PropertyType=Info) or
((P^.PropertyType^.Kind=Info^.Kind) and
(P^.PropertyType^.Name=Info^.Name)
) )
) or
( (Info^.Kind=tkClass) and
(P^.PropertyType^.Kind=tkClass) and
TypeData^.ClassType.InheritsFrom(
GetTypeData(P^.PropertyType)^.ClassType)
)
then
if ((P^.PersistentClass=nil) or ((Obj<>nil) and (Obj.InheritsFrom(P^.PersistentClass))))
and ((P^.PropertyName='') or (CompareText(P^.PropertyName,PropName)=0))
then then
if ((P^.PersistentClass=nil) or ((Obj<>nil) and (Obj.InheritsFrom(P^.PersistentClass)))) if (C=nil) or // see if P is better match than C
and ((P^.PropertyName='') or (CompareText(PropInfo^.Name,P^.PropertyName)=0)) ((C^.PersistentClass=nil) and (P^.PersistentClass<>nil)) or
((C^.PropertyName='') and (P^.PropertyName<>''))
or // P's proptype match is exact,but C's does not
((C^.PropertyType<>Info) and (P^.PropertyType=Info))
or // P's proptype is more specific than C's proptype
((P^.PropertyType<>C^.PropertyType) and
(P^.PropertyType^.Kind=tkClass) and
(C^.PropertyType^.Kind=tkClass) and
GetTypeData(P^.PropertyType)^.ClassType.InheritsFrom(
GetTypeData(C^.PropertyType)^.ClassType))
or // P's component class is more specific than C's component class
((P^.PersistentClass<>nil) and (C^.PersistentClass<>nil) and
(P^.PersistentClass<>C^.PersistentClass) and
(P^.PersistentClass.InheritsFrom(C^.PersistentClass)))
then then
if (C=nil) or // see if P is better match than C C:=P;
((C^.PersistentClass=nil) and (P^.PersistentClass<>nil)) or Inc(I);
((C^.PropertyName='') and (P^.PropertyName<>'')) end;
or // P's proptype match is exact,but C's does not if C<>nil then
((C^.PropertyType<>PropType) and (P^.PropertyType=PropType)) Result:=C^.EditorClass
or // P's proptype is more specific than C's proptype else begin
((P^.PropertyType<>C^.PropertyType) and if (Info^.Kind<>tkClass)
(P^.PropertyType^.Kind=tkClass) and or (TypeData^.ClassType.InheritsFrom(TPersistent))
(C^.PropertyType^.Kind=tkClass) and or (TypeData^.PropCount > 0) then
GetTypeData(P^.PropertyType)^.ClassType.InheritsFrom( Result:=PropClassMap[Info^.Kind]
GetTypeData(C^.PropertyType)^.ClassType)) else
or // P's component class is more specific than C's component class Result:=nil;
((P^.PersistentClass<>nil) and (C^.PersistentClass<>nil) and
(P^.PersistentClass<>C^.PersistentClass) and
(P^.PersistentClass.InheritsFrom(C^.PersistentClass)))
then
C:=P;
Inc(I);
end;
if C<>nil then
Result:=C^.EditorClass
else begin
if (PropType^.Kind<>tkClass)
or (GetTypeData(PropType)^.ClassType.InheritsFrom(TPersistent))
or (GetTypeData(PropType)^.PropCount > 0) then
Result:=PropClassMap[PropType^.Kind]
else
Result:=nil;
end;
end; end;
if (Result<>nil) and Result.InheritsFrom(THiddenPropertyEditor) then if (Result<>nil) and Result.InheritsFrom(THiddenPropertyEditor) then
Result:=nil; Result:=nil;