Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

caption of labels

Status
Not open for further replies.

fluppe689

Programmer
Jul 11, 2008
75
BE
Hi,
Dear Experts,

Is it possible get in a cursor file the caption of all labels, checkboxes, commandboxes of a certain form


Wfg,

Filip Merlier
 
A form is already a table

USE some.scx
Browse

Objname has the name of the object, Properties has all it's nondefault properties, you'll need to extract the line Caption = ... from that memo.

So one simple way would be USE the SCX and then
BROWSE FOR "Caption" $ Properties

Then there are objects on a form, which inherit their caption from a parent form class. That'll be in that parent form class in a VCX, if there is one. Also each conrol can be a class having set it's caption within the class. The SCX will then not override that.

So it's harder to do. Not impossible but it's harder to do.
It's much easier to simply address the caption property at runtime.

Bye, Olaf.


 
You could do something like this ugly query:
Code:
SELECT ; 
   CAST(class as Character(25)) as cType, ;
   CAST(SUBSTR(properties, AT('Caption', properties) + 11, AT('"', properties, 2) - AT('"', properties) -1) as character(50)) ;
   AS cCaption ;
   FROM SomeForm.SCX ;
   WHERE INLIST(baseclass, 'label', 'commandbutton', 'checkbox')


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
True, Dave.

But that doesn't account for inherited or default values. In both such cases the properties will not contain a caption, you'd need to join base forms and control classes, this makes it not possible to do in one SQL statement, as you can't have a dynamic number of joins or even recursion in VFP SQL. As inheritance can go very many levels, it's not predictive how many VCXes and which ones you'd need to join.

It's of course possible to also extract classloc file info and query in those files, too and put this into a recursive function.

There is one other thing you can do:
Code:
*CD (...insert your forms directory here...)
Modify Form someform.scx nowait

Local loForm
ASelObj(aForm,1)
loForm = aForm[1]
ListCaptions(loForm)

Procedure ListCaptions(toObject)
   Local loControl
   ? toObject.name
   For Each loControl in toObject.Objects FoxObject
      If PemStatus(loControl,'Caption',5)
         ? '"'+GetPem( loControl,'Caption')+'" is the caption of '+loControl.Name+', which is an object of the class '+loControl.Class
         * at this line you may fill a cursor with the values loControl.Caption, loControl.Name, loControl.Class, and whatever else of the control object interests you in the result
      EndIf
      If PemStatus(loControl,'Objects',5)
         ListCaptions(loControl)
      EndIf 
   EndFor
EndProc

Bye, Olaf.
 
Of course, for every idea, there is always a bazillion options and what-ifs. My query merely supplied an answer to the simple question stated.

Another option may be to use the "Code References" tool and export the listing.
Of course, if there is a form sub-classed in a .vcx somewhere in a sub-directory a distant server, Code References may not find it.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Well, just the same applies to the simples idea of browsing the scx file as table.
In most cases the caption text is defined on the last level, not inherited and not the default, so you're right.

But if remote form isn't available the project also can't be compiled, and a compilable project is the normal case.

The question is, what for do you need such a list? If it's about internationalisation, the best practice is to define a translation table and at runtime in init lookup the original caption in that table to retreive and set the same text in the current user language. If you automatically add texts you don't find at lookup you can translate them. Captions are just a beginning in that topic of internationalisation.

All needed for that matter is INTL toolkit.

Bye, Olaf.
 
Why go to the SCX for something like this? As Olaf says, you've got a problem walking up the class hierarchy there.

Why not use a builder that operates on the form opened in the form designer? You may need to recurse through containers, but iterate the controls. For ever control encountered, if the control has a caption property insert it into the cursor.

Seems like a lot less work.
 
The question is for what purpose you need the list of captions. I already addressed translation/internationalisation, but if it's for search&replace, both Code References and GoFish can be used to search also or only in captions.

You may also take a look at VFPX Conrol Renamer by Tamar Granor. You can get the source code, and Tamar works with ASELOBJ and AMEMBERS. This tool rather is about contorl names instead of captions, but the principle is the same.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top