How can I create a fake integer property?

  

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);
end;

procedure AddOrderProperty.FilterProperties(const ASelection:IDesignerSelections; const ASelectionProperties:IInterfaceList);
var OrderProperty: ControlOrderPropertyObj;
begin
if ASelection.Count<>1 then Exit;

if ASelection[0] is TControl then begin
if not (TControl(ASelection[0]).Parent is OrderLayoutObj) then Exit;

OrderProperty:=ControlOrderPropertyObj.Create(inherited Designer,1);
OrderProperty.Control:=TControl(ASelection[0]);
ASelectionProperties.Add(OrderProperty as IProperty);
end;
end;

I also don’t think that there’s a problem with my Register procedure:
procedure Register;
begin
DesignIntf.RegisterSelectionEditor(TControl,AddOrderProperty);
end;

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)
private
OrderControl: OrderLayoutObj;
ControlF: TControl;
procedure Control_Set(C:TControl);
protected
function GetEditValue(out Value:string):Boolean;
public
function GetName:string; override;
function GetValue:string; override;
procedure SetValue(const Value:string); override;
property Control:TControl read ControlF write Control_Set;
end; {AddControlFilter}

procedure ControlOrderPropertyObj.Control_Set(C:TControl);
begin
ControlF:=C;
OrderControl:=C.Parent as OrderLayoutObj;
end;

function ControlOrderPropertyObj.GetEditValue(out Value:string):Boolean; //This is a copy of the method from the article.
begin
Value:=GetValue;
Result:=True;
end;

function ControlOrderPropertyObj.GetName:string;
begin
Result:=’ControlIndex’;
end;

function ControlOrderPropertyObj.GetValue:string;
begin
GetValue:=OrderControl.PositionOf(Control).ToString;
end;

procedure ControlOrderPropertyObj.SetValue(const Value:string);
begin
OrderControl.ChangePosition(Control,Value.ToInteger);
end;

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;
begin
Result := FPropList^[0].PropInfo^.PropType^;
end;

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.

Comments are closed.