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

@ -1367,6 +1367,7 @@ procedure GetPersistentProperties(AItem: TPersistent;
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,20 +2208,18 @@ 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
tkInteger:
begin
Editor:=TIntegerPropertyEditor.Create(PropertyHook,1);
Editor.SetRecordFieldEntry(0, PByte(FRecordData)+Field^.FieldOffset, Field^.Name, FieldTypeInfo); Editor.SetRecordFieldEntry(0, PByte(FRecordData)+Field^.FieldOffset, Field^.Name, FieldTypeInfo);
Editor.Initialize; Editor.Initialize;
if ((PropCount > 1) and not (paMultiSelect in Editor.GetAttributes))
or not Editor.ValueAvailable
then begin
Editor.Free;
end else begin
Proc(Editor); Proc(Editor);
end; end;
else
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,8 +2804,6 @@ end;
function GetEditorClass(PropInfo:PPropInfo; Obj:TPersistent): TPropertyEditorClass; function GetEditorClass(PropInfo:PPropInfo; Obj:TPersistent): TPropertyEditorClass;
var var
PropType:PTypeInfo;
P,C:PPropertyClassRec;
I: Integer; I: Integer;
begin begin
Result := nil; Result := nil;
@ -2824,32 +2815,42 @@ begin
end; end;
end; end;
end; end;
if Result=nil then begin Result:=GetEditorClass(PropInfo^.Name,PropInfo^.PropType,Obj);
PropType:=PropInfo^.PropType; end;
function GetEditorClass(PropName: shortstring; Info: PTypeInfo; Obj: TPersistent
): TPropertyEditorClass;
var
P, C: PPropertyClassRec;
I: Integer;
TypeData: PTypeData;
begin
Result := nil;
I:=0; I:=0;
C:=nil; C:=nil;
TypeData:=GetTypeData(Info);
while I < PropertyClassList.Count do begin while I < PropertyClassList.Count do begin
P:=PropertyClassList[I]; P:=PropertyClassList[I];
if ((P^.PropertyType=PropType) or if ((P^.PropertyType=Info) or
((P^.PropertyType^.Kind=PropType^.Kind) and ((P^.PropertyType^.Kind=Info^.Kind) and
(P^.PropertyType^.Name=PropType^.Name) (P^.PropertyType^.Name=Info^.Name)
) )
) or ) or
( (PropType^.Kind=tkClass) and ( (Info^.Kind=tkClass) and
(P^.PropertyType^.Kind=tkClass) and (P^.PropertyType^.Kind=tkClass) and
GetTypeData(PropType)^.ClassType.InheritsFrom( TypeData^.ClassType.InheritsFrom(
GetTypeData(P^.PropertyType)^.ClassType) GetTypeData(P^.PropertyType)^.ClassType)
) )
then then
if ((P^.PersistentClass=nil) or ((Obj<>nil) and (Obj.InheritsFrom(P^.PersistentClass)))) if ((P^.PersistentClass=nil) or ((Obj<>nil) and (Obj.InheritsFrom(P^.PersistentClass))))
and ((P^.PropertyName='') or (CompareText(PropInfo^.Name,P^.PropertyName)=0)) and ((P^.PropertyName='') or (CompareText(P^.PropertyName,PropName)=0))
then then
if (C=nil) or // see if P is better match than C if (C=nil) or // see if P is better match than C
((C^.PersistentClass=nil) and (P^.PersistentClass<>nil)) or ((C^.PersistentClass=nil) and (P^.PersistentClass<>nil)) or
((C^.PropertyName='') and (P^.PropertyName<>'')) ((C^.PropertyName='') and (P^.PropertyName<>''))
or // P's proptype match is exact,but C's does not or // P's proptype match is exact,but C's does not
((C^.PropertyType<>PropType) and (P^.PropertyType=PropType)) ((C^.PropertyType<>Info) and (P^.PropertyType=Info))
or // P's proptype is more specific than C's proptype or // P's proptype is more specific than C's proptype
((P^.PropertyType<>C^.PropertyType) and ((P^.PropertyType<>C^.PropertyType) and
(P^.PropertyType^.Kind=tkClass) and (P^.PropertyType^.Kind=tkClass) and
@ -2867,14 +2868,13 @@ begin
if C<>nil then if C<>nil then
Result:=C^.EditorClass Result:=C^.EditorClass
else begin else begin
if (PropType^.Kind<>tkClass) if (Info^.Kind<>tkClass)
or (GetTypeData(PropType)^.ClassType.InheritsFrom(TPersistent)) or (TypeData^.ClassType.InheritsFrom(TPersistent))
or (GetTypeData(PropType)^.PropCount > 0) then or (TypeData^.PropCount > 0) then
Result:=PropClassMap[PropType^.Kind] Result:=PropClassMap[Info^.Kind]
else else
Result:=nil; 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;
end; end;