Author Topic: Trying to write to a label on a form  (Read 8522 times)

cappy2112

  • Community Member
  • Posts: 91
  • Hero Points: 0
Trying to write to a label on a form
« on: January 19, 2007, 10:13:08 PM »

I'm trying to write to a label I've put on a form, but can't seem to get the syntax correct.
The examples in the help file regarding forms and controls are very weak, so I'm just guessing at a lot of this.

The form I've saved is called TC_MessageBox. There are one button, and one label on the form.

defeventtab TC_MessageBox;
void ctlcommand1.lbutton_up()
{
   ctllabel1.caption="The source files have been processed";
 
}

When I press F12, the error message displayed is
Control 'caption' must be declared or cannot be a member of a non-struct/union/class type


Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Trying to write to a label on a form
« Reply #1 on: January 19, 2007, 10:38:45 PM »
You need to manually add

_control ctllabel1;

or you might be able to do this

p_active_form.ctllabel1.caption='...';

Graeme
 

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Trying to write to a label on a form
« Reply #2 on: January 19, 2007, 10:40:20 PM »
Oops, didn't read that carefully enough  - it's p_caption, not caption.

Graeme

cappy2112

  • Community Member
  • Posts: 91
  • Hero Points: 0
Re: Trying to write to a label on a form
« Reply #3 on: January 19, 2007, 10:57:08 PM »
Oops, didn't read that carefully enough  - it's p_caption, not caption.

Graeme


How does one infer that from this (taken verbatim rom the Help File, under Label Control)

Label control
Label control is for displaying text in any font. Labels can be aligned left, right, centered horizontally, centered vertically, or centered horizontally and vertically. If you do not need to align the label, set the p_auto_size property to TRUE to ensure that the text fits inside the window. A common use of a label control is to place it to the left of a text box to tell the user about what goes in the text box. Select the Label control and use the up, down, left, and right arrow keys to center the label to the text box.

For a complete list of label control properties, methods, and events, from the main menu, select Help > Macro Functions by Category.




Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Trying to write to a label on a form
« Reply #4 on: January 19, 2007, 11:44:07 PM »
Quote
How does one infer that from this (taken verbatim rom the Help File, under Label Control)

...
For a complete list of label control properties, methods, and events, from the main menu, select Help > Macro Functions by Category.

Good question.  If you go to "macro functions by category", you'll see "Label methods, properties" in the list.  If you click properties, you'll get a big list of names all starting with p_    - however, p_caption just happens to be missing from the list.  This is a error in the help - it should have p_caption there as a Label property.  If you go to "Command button" -> properties - you'll see p_caption there - click on the p_caption link and you'll see it applies to Label.  Also, in the help index you'll see a big list of p_ properties  - not that that's any help in determining what to use with Label.

If you look in vusrobjs.e (in your config folder), you'll see a "text description" of your form, including the setting of properties.  vusrobjs.e only gets updated when you close slick or do a save_config.  BTW - on the macro menu, you can use "insert form menu or source" to insert the "text description" of a form into a source file.

Graeme

cappy2112

  • Community Member
  • Posts: 91
  • Hero Points: 0
Re: Trying to write to a label on a form
« Reply #5 on: January 20, 2007, 12:08:45 AM »
Quote
How does one infer that from this (taken verbatim rom the Help File, under Label Control)

...
For a complete list of label control properties, methods, and events, from the main menu, select Help > Macro Functions by Category.

Good question.  If you go to "macro functions by category", you'll see "Label methods, properties" in the list.  If you click properties, you'll get a big list of names all starting with p_    - however, p_caption just happens to be missing from the list.

Graeme

Again, this has been  very helpful

cappy2112

  • Community Member
  • Posts: 91
  • Hero Points: 0
Re: Trying to write to a label on a form
« Reply #6 on: January 20, 2007, 01:31:54 AM »
Oops, didn't read that carefully enough  - it's p_caption, not caption.

Graeme


When I reference ctllabel1 in a function that doesn't start with _command, it's ok.
When I reference ctllabel1 in a function that starts with _command, ctllabel1  cannot be found.
(this may be a coincidence, but it's the only difference I can see)

defeventtab TC_MessageBox;
_command void StartPreprocess() name_info(',')
{
   int bufferCount;
   _control ctllabel1;

   bufferCount = TCGetBufferCount();
   show('TC_MessageBox');
   Msg =bufferCount " buffers are open";
   p_active_form.ctllabel1.p_caption = Msg;
}

Control ctllabel1 referenced but does not exist

What am I doing wrong?


Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Trying to write to a label on a form
« Reply #7 on: January 20, 2007, 02:31:48 AM »
I assume that's a runtime error.  Probably you should do this - as you can see in the example with the show command (type help show on slick cmd line).

Code: [Select]
int wid = show('TC_MessageBox');
   Msg =bufferCount " buffers are open";
   if (wid >= 0)
       wid.ctllabel1.p_caption = Msg;

Probably the difference is that a different window is active when show returns if the code is called from a _command (e.g. from the command line) than if it's called from whereever you're calling the function when it's not a command.

show appears to switch the window_id back to the id of the window that was active when it returns.  I recently also discovered that when show is called, all the events relating to construction and on_load etc. are called before the call to show returns - so I guess that means the show command runs event loops to get all that done.

See also the topic "objects and instances" in the help - try help _control on the cmd line.

Graeme
« Last Edit: January 20, 2007, 02:33:28 AM by Graeme »