Text Object Variable Names

297 views
Skip to first unread message

MrChimp

unread,
Jun 27, 2011, 7:41:00 AM6/27/11
to MapInfo-L
In MapBasic you can create a text object in a layout window by using
the "Create text" statement. You can also use the same statement to
update this object.

I am working on a tool that creates several plans by repeatedly
exporting a layout window as an image file. Between each export I
would like to update the text in the layout window to indicate the
reference number of the site.

How do I go about finding the object's variable name?

e.j.h.polle

unread,
Jun 27, 2011, 8:32:04 AM6/27/11
to MapInfo-L
Hi Chimp,

You can use a variable to create a text in a layout.

So instead of using: Create Text "Map 1"

you should use:

Global sMapTitle as String

sMapTitle = "Map 1"

Create Text sMapTitle

In this way you only have to change the content of the variable before
exporting the next layout window.

HTH,

Egge-Jan

MrChimp

unread,
Jun 27, 2011, 11:46:51 AM6/27/11
to MapInfo-L
Hello

Thanks for helping...

Are you saying that updating a variable will change the existing text
in the layout window?

Or are you just pointing out the fact that I can use a variable to
create the text?

I guess I could recreate the layout window each time but that doesn't
seem very efficient. What I am trying to do is edit the text in place.

Thanks again!

Peter Horsbøll Møller

unread,
Jun 27, 2011, 1:44:21 PM6/27/11
to mapi...@googlegroups.com
MrChimp,

In your application you could remember the rowid of your text object and just update this for each new layout you want to print.
Combining this with Egge-Jan's suggestion would look like this:
1. Have a modular variable to hold the rowid of the text object to update
2. Have a procedure to find the rowid of the text object - this must only be called once (unless you delete from your layout - that might not even make a difference either)
3. Have a procedure that can update the text object, using the rowid read

'**Dim a variable to hold the RowID of the text object
Dim mnRowIDRefIDText As Integer

'**Procedure that is called to set the rowid of the text object
'**assumes that the frontwindow is the layout to update
'**assumes that the 
Sub HereTheRowIDOfTheTextObjectIsSet

Dim sLayoutTable As String
Dim oText As Object
Dim aObj As Alias

   sLayoutTable = WindowInfo(FrontWindow(), WIN_INFO_TABLE)
   aObj = sLayoutTable + ".OBJ"

   Fetch First From sLayoutTable
   Do Until EOT(sLayoutTable)
      oText = aObj
      Do Case ObjectInfo(oText, OBJ_INFO_TYPE)
         Case OBJ_TYPE_TEXT
            Do Case ObjectInfo(oText, OBJ_INFO_TEXTSTRING) 
               Case "[REFNUMBER]"
                  mnRowIDRefIDText
               'Case .. please add other cases if you need to
            End Case
      End Case
   Loop

End Sub


'**Procedure that is called to update the content of the layout window
'**assumes that the frontwindow is the layout to update
'**it also assumes that you have set the rowid of the text object some where else
Sub HereTheLayoutWillBeUpdated()

Dim sLayoutTable As String
Dim oText As Object
Dim aObj As Alias

   sLayoutTable = WindowInfo(FrontWindow(), WIN_INFO_TABLE)
   aObj = sLayoutTable + ".OBJ"
   Fetch Rec mnRowIDRefIDText From sLayoutTable
   oText = aObj
   Alter Object oText Info OBJ_INFO_TEXTSTRING, "Here goes some new values" 
   Update sLayoutTable 
      Set OBJ = oText 
      Where ROWID = mnRowIDRefIDText

End Sub

I hope this makes sense

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo


2011/6/27 MrChimp <chim...@gmail.com>
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

Peter Horsbøll Møller

unread,
Jun 27, 2011, 1:45:31 PM6/27/11
to mapi...@googlegroups.com
PS: I forgot to mention that your layout should have a placeholder for your text, in  my example it is the text [REFNUMBER] that should exist in the layout template.

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo



2011/6/27 Peter Horsbøll Møller <mapi...@horsboll-moller.dk>

MrChimp

unread,
Jun 28, 2011, 9:35:54 AM6/28/11
to MapInfo-L
Thanks Peter, that's works great! (The missing "fetch next" in the "do
until" caught me out though! Infinite loop!)

Could you explain to me the purpose of "Create Text Into Variable"?

I thought that would make what I am trying to do very easy but I can't
find a use for it at all.

Thanks again!
Jake


On Jun 27, 6:45 pm, Peter Horsbøll Møller <mapinf...@horsboll-
moller.dk> wrote:
> PS: I forgot to mention that your layout should have a placeholder for your
> text, in  my example it is the text [REFNUMBER] that should exist in the
> layout template.
> Peter Horsbøll Møller
> Pitney Bowes Business Insight - MapInfo
>
> 2011/6/27 Peter Horsbøll Møller <mapinf...@horsboll-moller.dk>
> > 2011/6/27 MrChimp <chimp...@gmail.com>

Peter Horsbøll Møller

unread,
Jun 29, 2011, 3:12:24 AM6/29/11
to mapi...@googlegroups.com
Jake,
Sorry for the missing Fetch Next - I must admit that I tend to forget those - that's why I have that loop as a template in UEStudio :-)

Create Text Into Variable can be used to create new text that you want to add to a layout for instance - you can of course also do this with the Create Text Into Window.
Can't remember from the top of my head where I have used the Create Text Into Variable.

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo


2011/6/28 MrChimp <chim...@gmail.com>

MrChimp

unread,
Jun 29, 2011, 4:12:09 AM6/29/11
to MapInfo-L
If you create the text into a variable, how do you then add it to a
window?


On Jun 29, 8:12 am, Peter Horsbøll Møller <mapinf...@horsboll-
moller.dk> wrote:
> Jake,
> Sorry for the missing Fetch Next - I must admit that I tend to forget those
> - that's why I have that loop as a template in UEStudio :-)
>
> Create Text Into Variable can be used to create new text that you want to
> add to a layout for instance - you can of course also do this with the
> Create Text Into Window.
> Can't remember from the top of my head where I have used the Create Text
> Into Variable.
>
> Peter Horsbøll Møller
> Pitney Bowes Business Insight - MapInfo
>
> 2011/6/28 MrChimp <chimp...@gmail.com>

Peter Horsbøll Møller

unread,
Jun 29, 2011, 5:12:22 AM6/29/11
to mapi...@googlegroups.com
Insert Into sLayoutTable (OBJ) Values (oText)

Where sLayoutTable is a variable holding the name of the table "behind" the layout window

Peter Horsbøll Møller
Pitney Bowes Business Insight - MapInfo


2011/6/29 MrChimp <chim...@gmail.com>

MrChimp

unread,
Jun 29, 2011, 6:13:03 AM6/29/11
to MapInfo-L
D'oh, of course!

I had been hoping beyond reason that it would leave you with a
variable that would be a reference to the text object, even once it
was in the layout window. Ah well, it's a bit convoluted but it all
works.

Thanks again!


On Jun 29, 10:12 am, Peter Horsbøll Møller <mapinf...@horsboll-
moller.dk> wrote:
> Insert Into sLayoutTable (OBJ) Values (oText)
>
> Where sLayoutTable is a variable holding the name of the table "behind" the
> layout window
>
> Peter Horsbøll Møller
> Pitney Bowes Business Insight - MapInfo
>
> 2011/6/29 MrChimp <chimp...@gmail.com>

Eric Blasenheim

unread,
Jun 29, 2011, 11:57:07 AM6/29/11
to MapInfo-L
Just to hone in on the concept here which should help you in anything
else you do in Professional/MapBasic, a variable is just a way of
referencing some location of data in memory to reuse.
You store data in a variable and can reuse it for any operation that
takes a variable, like inserting or updating a table. You can also use
a variable as a location to store data from a table, such as a fetch.
However, because variables represent memory and are not persistent,
they never represent a direct link to a table.

So if you read data by a fetch, the data exists still in the table and
the variable. They are not linked. You may change the data in the
variable. It does not affect the row in the table.
Or you can insert or update a row by a variable. They are momentarily
the same. You can change the variable and use it for a different
purpose. The data in the table is not changed.

This comes up frequently when people use Alter Object. That changes
the variable. To change the table data one must use a table operation
like Insert or Update.

Eric Blasenheim
PBBI (MapInfo)
> > >http://groups.google.com/group/mapinfo-l?hl=en- Hide quoted text -
>
> - Show quoted text -

Nyall Dawson

unread,
Jun 29, 2011, 7:22:59 PM6/29/11
to mapi...@googlegroups.com
You might get some value out of this tool I wrote a little while back. It can be used to automatically create a batch set of printouts of a layout which are driven by the objects in a chosen table. One neat feature is that any text objects on the layout which begin with an "=" sign can contain expressions which are evaluated on-the-fly. For instance, you can have a label containing something like

=ref_no + " " + site_name + " (" +  Str$(CurDate()) +")"

and the string will be evaluated for each page created by the routine.

There's a little bit of messiness in the code which could be fixed -- after I got it to an operational stage I haven't found time to go back and clean it up!

Hope it's of some use,

Nyall Dawson



data_driven_pagev5.mb
Reply all
Reply to author
Forward
0 new messages