Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Testing a control for a property
Wed, Oct 25 2017 8:26 AMPermanent Link

Matthew Jones

Is there a way to test if a component or control has a particular property? Such that I can traverse the components and find all those with a particular property?

And asking this made me remember I'd done something, and Tim had said use caution, but to answer my own question, which I will post for myself and others when needed:

(excuse the mix of naming conventions - copy and paste does that for me sometimes!)

procedure DumpTabs(szInfo : String; xComponent : TControl);
var
   i: integer;
   c: TControl;
   bTabStop : Boolean;
   nTabIndex : Integer;
   nLayoutOrder : Integer;
   TempType: Integer;
begin
   if szInfo = '' then
       DebugReport('Component LayoutOrder/TabIndex');
   TempType := xComponent.PropertyType('TabStop');
   if (TempType = TYPE_INFO_BOOLEAN) then
   begin
       bTabStop := xComponent.GetProperty('TabStop');
       nTabIndex := xComponent.GetProperty('TabOrder');
       nLayoutOrder := xComponent.GetProperty('LayoutOrder');
       if (bTabStop) then
       begin
           DebugReport(szInfo + xComponent.Name + ' ' + IntToStr(nLayoutOrder) + '/' + IntToStr(nTabIndex) {+ ' ' + IntToStr(Ord(bTabStop))});
       end;
   end;
   for i := 0 to xComponent.ControlCount - 1 do
   begin
       c := xComponent.Controls[i];
       DumpTabs(szInfo + xComponent.Name + '-', c);
   end;
end;

--

Matthew Jones
Wed, Oct 25 2017 12:07 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< And asking this made me remember I'd done something, and Tim had said use caution, but to answer my own question, which I will post for myself and others when needed: >>

Caveats: this only covers published properties, is used internally by the persistence layer, provides zero type checking because of the use of variants and can cause runtime errors, and is subject to change at any time.

Tim Young
Elevate Software
www.elevatesoft.com
Image