I’m trying to create a fake or pseudo property for child controls, and have tried to follow this article: https://edn.embarcadero.com/article/33448
However, that was written some years ago, so I don’t know how much Delphi might have changed since then in a way that could matter here.
Unlike the goal of that article, I’m trying to have a number property that is essentially the index of the control in its parent. This is for when a particular custom control (OrderLayoutObj) is the parent (although it might have applicability in other cases where I want to change the order of a control in its parent’s Children list without having to manually reorder the controls in the .fmx.)
In place of the article’s TAddPropertyFilter, this is my declaration and implementation. It matches the article’s one pretty closely, and I don’t think there is a problem with it. (Sorry for my umm, unconventional, naming and formatting.)
AddOrderProperty = class(TSelectionEditor, ISelectionPropertyFilter)
procedure FilterProperties(const ASelection: IDesignerSelections; const ASelectionProperties:IInterfaceList);
procedure AddOrderProperty.FilterProperties(const ASelection:IDesignerSelections; const ASelectionProperties:IInterfaceList);
var OrderProperty: ControlOrderPropertyObj;
if ASelection.Count<>1 then Exit;
if ASelection is TControl then begin
if not (TControl(ASelection).Parent is OrderLayoutObj) then Exit;
ASelectionProperties.Add(OrderProperty as IProperty);
I also don’t think that there’s a problem with my Register procedure:
I think the real problem is in my equivalent of the article’s TBaseComponentPropertyEditor and its descendant TControlParentProperty which were designed to allow a control to be selected. Instead of using that I’ve based it on TIntegerProperty, given that my additional property is an integer, and not knowing if the article’s author used what he did because he didn’t have a better descendant available at the time of the article.
(I did try try basing it on TBasePropertyEditor, but that didn’t work either, although the property did appear in the Object Inspector, and then produced an error. I don’t recall the exact details, though.)
ControlOrderPropertyObj = class(TIntegerProperty)
function GetEditValue(out Value:string):Boolean;
function GetName:string; override;
function GetValue:string; override;
procedure SetValue(const Value:string); override;
property Control:TControl read ControlF write Control_Set;
OrderControl:=C.Parent as OrderLayoutObj;
function ControlOrderPropertyObj.GetEditValue(out Value:string):Boolean; //This is a copy of the method from the article.
procedure ControlOrderPropertyObj.SetValue(const Value:string);
I think the problem is with another IProperty or other method that I haven’t overridden, but the only clue as to which one is that it’s producing an access violation (when clicking on the child component in the form editor) in line 752 of DesignEditors.pas. That’s on the Result:= line of this method:
function TPropertyEditor.GetPropType: PTypeInfo;
Result := FPropList^.PropInfo^.PropType^;
Although I’ve done it years ago, I’ve been unable to debug the design-time .bpl by setting Run>Parameters>Host name to Delphi itself.