Board index » delphi » Getting list of controls liked to TDataSource

Getting list of controls liked to TDataSource

Is there a way to get a list of data-aware controls linked to a given
TDataSource component? I need a solution that will work without knowing
ahead of time what form to look in for the controls.
 

Re:Getting list of controls liked to TDataSource


Quote
David Emami wrote in message

<8F4DA028Fdavideretailpro...@news.retailpro.com>...

Quote
>Is there a way to get a list of data-aware controls linked to a given
>TDataSource component? I need a solution that will work without
knowing
>ahead of time what form to look in for the controls.

There's no way to go from the TDatasource end. The only way I can see
is to iterate over all the controls and see if it is data-aware (using
RTTI to find out if it has a Datasource property) and, if so, see if
the Datasource property is the TDatasource you're looking for.

--
Wayne Niddery - WinWright Consulting
RADBooks - http://members.home.net/wniddery/
You have a Right to Free Speech, but not the right to make me listen,
nor to use my property as a soapbox.

Re:Getting list of controls liked to TDataSource


Try something like the following. This code will scan all components on all
forms and determine if the component has a DataSource property. If it does,
the value of the DataSource property is assigned to the variable
ThisDataSource.

for I := 0 to Screen.FormCount - 1 do
  if Screen.Forms[I] is TCustomForm then
    with Screen.Forms[I] as TCustomForm do
      for J := 0 to Component.Count - 1 do
        if IsPublishedProb(Components[J], 'DataSource') then
        begin
          ThisDataSource := GetObjectProp(Components[J], 'DataSource') as
TDataSource;
          if ThisDataSource = SomeOtherDataSource then...
        end;

--
Bill Todd (TeamB)
(Questions received via email cannot be answered.)

Re:Getting list of controls liked to TDataSource


Bill Todd \(TeamB\) <b...@nospam.dbginc.com> wrote in
<8hrnv3$23...@bornews.borland.com>:

Quote
>Try something like the following. This code will scan all components on
>all forms and determine if the component has a DataSource property. If
>it does, the value of the DataSource property is assigned to the
>variable ThisDataSource.

>for I := 0 to Screen.FormCount - 1 do
>  if Screen.Forms[I] is TCustomForm then
>    with Screen.Forms[I] as TCustomForm do
>      for J := 0 to Component.Count - 1 do
>        if IsPublishedProb(Components[J], 'DataSource') then
>        begin
>          ThisDataSource := GetObjectProp(Components[J], 'DataSource')
>          as
>TDataSource;
>          if ThisDataSource = SomeOtherDataSource then...
>        end;

Thanks, both to you and to Wayne Niddery (who also responded). That's
basically what I figured I've have to resort to, and what I ultimately
did, but it's so brute-force. (No offense intended, it's the best way I
can see to solve the problem given the constraints).

What I'd rather do (and which someone who replied by email pointed out to
me) is look at the DataLinks property of TDataSource, but this is
protected, not public, so I can't get to it without either modifying
db.pas or descending from TDataSource, neither of which is something I
want to do. Which brings me to one of those rare things in Delphi that
really really annoy me: properties/methods of VCL classes being declared
at too low a level of visibility. I run into this every so often and it's
frustrating to  have to come up with a (usually slow or complicated or
kludgy) workaround to get done what I want done, when the means to do it
quickly, easily, and elegantly are right there in front of me, kept out
of my grasp merely by virtue of being private or protected instead of
public.

Re:Getting list of controls liked to TDataSource


Quote
David Emami wrote in message

<8F52AAA90davideretailpro...@news.retailpro.com>...

Quote

>What I'd rather do (and which someone who replied by email pointed
out to
>me) is look at the DataLinks property of TDataSource, but this is
>protected, not public, so I can't get to it without either modifying
>db.pas or descending from TDataSource, neither of which is something
I
>want to do.

And you'd hit a dead-end anyway because TDatalink doesn't know the
TField it's connected to. <g>

--
Wayne Niddery - WinWright Consulting
RADBooks - http://members.home.net/wniddery/
You have a Right to Free Speech, but not the right to make me listen,
nor to use my property as a soapbox.

Re:Getting list of controls liked to TDataSource


On Tue, 13 Jun 2000 20:19:18 -0400, "Wayne Niddery (TeamB)"

Quote
<winwri...@chaffhome.com> wrote:
>And you'd hit a dead-end anyway because TDatalink doesn't know the
>TField it's connected to. <g>

Wayne,
Unless it's a TFieldDataLink?

Jan

Re:Getting list of controls liked to TDataSource


Then how does TDataset.UpdateRecord find the associated DB controls?  I did
go to the source once and there is some protected function in the TDataset
which uses the TDataLink to find all the DB controls but now I forget how.

Ping

Wayne Niddery (TeamB) <winwri...@chaffhome.com> wrote in message
news:3946cc36@dnews...

Quote
> David Emami wrote in message
> <8F52AAA90davideretailpro...@news.retailpro.com>...

> >What I'd rather do (and which someone who replied by email pointed
> out to
> >me) is look at the DataLinks property of TDataSource, but this is
> >protected, not public, so I can't get to it without either modifying
> >db.pas or descending from TDataSource, neither of which is something
> I
> >want to do.

> And you'd hit a dead-end anyway because TDatalink doesn't know the
> TField it's connected to. <g>

> --
> Wayne Niddery - WinWright Consulting
> RADBooks - http://members.home.net/wniddery/
> You have a Right to Free Speech, but not the right to make me listen,
> nor to use my property as a soapbox.

Re:Getting list of controls liked to TDataSource


David,

Please kindly ignore my last post regarding the TDatalink dead-end, my
brain was having a little gas. <g>

--
Wayne Niddery - WinWright Consulting
RADBooks - http://members.home.net/wniddery/
You have a Right to Free Speech, but not the right to make me listen,
nor to use my property as a soapbox.

Re:Getting list of controls liked to TDataSource


Quote
Jan Sprengers wrote in message

<394887ab.502539...@forums.inprise.com>...

Quote
>On Tue, 13 Jun 2000 20:19:18 -0400, "Wayne Niddery (TeamB)"
><winwri...@chaffhome.com> wrote:

>>And you'd hit a dead-end anyway because TDatalink doesn't know the
>>TField it's connected to. <g>

>Wayne,

>Unless it's a TFieldDataLink?

Unless <g>

Another famous day for me.

--
Wayne Niddery - WinWright Consulting
RADBooks - http://members.home.net/wniddery/
You have a Right to Free Speech, but not the right to make me listen,
nor to use my property as a soapbox.

Re:Getting list of controls liked to TDataSource


Quote
David Emami <dav...@retailpro.com> wrote:
>What I'd rather do (and which someone who replied by email pointed out to
>me) is look at the DataLinks property of TDataSource, but this is
>protected, not public, so I can't get to it without either modifying
>db.pas or descending from TDataSource, neither of which is something I
>want to do. Which brings me to one of those rare things in Delphi that
>really really annoy me: properties/methods of VCL classes being declared
>at too low a level of visibility. I run into this every so often and it's
>frustrating to  have to come up with a (usually slow or complicated or
>kludgy) workaround to get done what I want done, when the means to do it
>quickly, easily, and elegantly are right there in front of me, kept out
>of my grasp merely by virtue of being private or protected instead of
>public.

It's possible to gain access to protected fields by defining a hack
class such as this:

type
  TDataSourceHack = class(TDataSource);

Then to access the DataLinks property, you can use a typecast
to gain access like this:

  TDataSourceHack(DataSource1).DataLinks

It's not necessary to install the hack class in the component
palette -- just add the type definition to your code in the same
unit as the typecast.  This only works with protected fields, not
private fields.  The reason it works is that descendants have access
to protected fields, and within a unit everything has access to
everything.  Since TDataSourceHack is defined in the same
unit as the typecast, you can access protected properties
such as DataLinks.

Hope this helps!

-Rich

Re:Getting list of controls liked to TDataSource


Hi Bill!

On Fri, 9 Jun 2000 14:35:53 -0700, "Bill Todd \(TeamB\)"

Quote
<b...@dbginc.com> wrote:
>for I := 0 to Screen.FormCount - 1 do
>  if Screen.Forms[I] is TCustomForm then
>    with Screen.Forms[I] as TCustomForm do
>      for J := 0 to Component.Count - 1 do
>        if IsPublishedProb(Components[J], 'DataSource') then
>        begin
>          ThisDataSource := GetObjectProp(Components[J], 'DataSource') as
>TDataSource;
>          if ThisDataSource = SomeOtherDataSource then...
>        end;

I tried some modified version of code you put here but it can not
compile. Where are IsPublishedProp and GetObjectProp functions
defined? They are not in the help index list...

tomi.

Re:Getting list of controls liked to TDataSource


In TypInfo.

Please do not cross post as this goes against the rules of use for the Borland
newsgroups (www.borland.com\newsgroups).  Thank you.

Quote
"Tomislav Karda?" wrote:

> I tried some modified version of code you put here but it can not
> compile. Where are IsPublishedProp and GetObjectProp functions
> defined? They are not in the help index list...

> tomi.

--
Jeff Overcash (TeamB)  
  (Please do not email me directly unless asked.  Thank You)    
A spider wanders aimlessly within the warmth of a shadow, not the regal creature
of border caves, but the poor, misguided, directionless familiar of some obscure
Scottish poet.  The mist crawls from the c{*word*7}like some primordial phantom of
romance To curl, under the cascade of neon pollen.  While I sit tied to the
phone like some expectant father, your carnation will rot in a vase.  (Fish)

Re:Getting list of controls liked to TDataSource


Hi Jeff!

On Sat, 15 Jul 2000 14:41:50 -0400, "Jeff Overcash (TeamB)"

Quote
<overc...@onramp.net> wrote:
>Please do not cross post as this goes against the rules of use for the Borland
>newsgroups (www.borland.com\newsgroups).  Thank you.

I'am sorry, I just replyed to the message Bill Todd posted and didn't
checked to see that there were two news groups in the destination. I
never cross post intentionaly.

tomi.

Re:Getting list of controls liked to TDataSource


Hi "Bill Todd \(TeamB\)" <b...@dbginc.com>!

On Sat, 15 Jul 2000 16:21:46 -0700, "Bill Todd \(TeamB\)"

Quote
<b...@dbginc.com> wrote:
>Add typinfo to your uses clause. This is the unit that contains all of the
>runtime type information methods.

It still can not compile (I have Delphi4 C/S sp2) ...
TypInfo unit does not contain your IsPublishedProp and GetObjectProp!

tomi.

Re:Getting list of controls liked to TDataSource


Hi Bill!

On Mon, 24 Jul 2000 18:24:24 -0700, "Bill Todd \(TeamB\)"

Quote
<b...@dbginc.com> wrote:
>That is because IsPublishedProperty was added in D5.

Oh, I see. Thanks!

tomi.

Other Threads