[Gambas-user] What type of control is it?
Bruce
bbruen at ...2308...
Mon Sep 30 10:01:44 CEST 2013
On Mon, 2013-09-30 at 09:26 +0200, Tobias Boege wrote:
> On Mon, 30 Sep 2013, Bruce wrote:
> > Aaaaarrrgghhh! I've done this a zillion times before but today I can't
> > find an example.
> >
> >
> > How do I get the type of the Application.CurrentControl control?
> >
> > It's not TypeOf() as that returns gb.Object
> > I need to know if it has a text or value so I can copy it to the
> > clipboard,
> >
>
> To get the type (class name) of an object (you were so close :-)):
>
> Object.Type(Application.CurrentControl)
>
> but you could also directly check for a Text or Value property:
>
> Dim hClass As Class = Object.Class(Application.CurrentControl)
>
> If hClass.Exist("Text") And If hClass["Text"].Kind = Class.Property Then
> HasText()
> Else If hClass.Exist("Value") And If hClass["Value"].Kind = Class.Property Then
> HasValue()
> Endif
>
> or probably a bit faster but a little ugly:
>
> Dim vValue As Variant
>
> Try vValue = Application.CurrentControl.Value
> If Not Error Goto _Found
> Try vValue = Application.CurrentControl.Text
> If Not Error Goto _Found
> NothingToCopy()
> Return
> _Found:
> CopyToClipboard()
>
> Regards,
> Tobi
Thanks Tobi. In fact, thanks twice.
I think we'll go for the second option as it will handle the dozens of
custom controls we use.
(Thinking a bit in the background... maybe it would be nice if all
controls had a "CurrentValue" property? ... then in cases like
this ... your third option could reduce to a Select
TypeOf(Application.CurrentControl.CurrentValue). I can even see that
working for gridded controls.)
Bruce
More information about the User
mailing list