Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 23 Oct 2014, 12:50
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Genie problem: storing strings in classes
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [3 Posts]  
Author Message
ProgRob

Joined: 13 Feb 2013
Posts: 14

PostPosted: Fri 13 Jun 2014, 04:55    Post subject:  Genie problem: storing strings in classes  

Hi all,

I am tearing my hair out on this. I am working on a project that, amongst other things, is reading in .desktop files and storing some of the information it finds in them. I'd like to use classes to store the info but I am getting some behaviour which I only half understand.

I've created a simple test program to demonstrate:
Code:
class Thing
   prop nameline : string = "** name line not found **"
   prop genericnameline : string = " generic name line not found **"

init
   line : string
   lngth : size_t
   var t = new Thing()
   var dis = new DataInputStream(File.new_for_path("/usr/share/applications/Geany-text-editor.desktop").read())
   while ((line = dis.read_line (out lngth, null)) != null)
      if line.has_prefix("Name=")
         t.nameline = line
      else if line.has_prefix("GenericName=")
         t.genericnameline = line
   print "We found\n  Name: %s\n  Generic name: %s", t.nameline, t.genericnameline

When I run this I get:
Code:
We found
  Name:
  Generic Name: XricName=Geany^ [[?1;2c

Not at all what I was expecting! However, when I run the following program which does not use classes:
Code:
init
   line : string
   lngth : size_t
   nameline : string = "** name line not found **"
   genericnameline : string = "** generic name line not found **"
   var dis = new DataInputStream(File.new_for_path("/usr/share/applications/Geany-text-editor.desktop").read())
   while ((line = dis.read_line (out lngth, null)) != null)
      if line.has_prefix("Name=")
         nameline = line
      else if line.has_prefix("GenericName=")
         genericnameline = line
   print "We found\n  Name: %s\n  Generic name: %s", nameline, genericnameline

I get the result I expect:
Code:
We found
  Name: Name=Geany text editor
  GenericName: GenericName=Geany

I think this is something to to with weak references but I cannot fathom out how to get the class to own the strings.

Can anyone advise?

Thanks,
Rob
Back to top
View user's profile Send private message 
ProgRob

Joined: 13 Feb 2013
Posts: 14

PostPosted: Fri 13 Jun 2014, 08:52    Post subject:  

OK, so I have found a solution that works.

In the class definition I simply drop the 'prop' and turn the properties into fields. My question is therefore now a simpler one: what is the different between a field and property in a Genie (and Vala) class?
Back to top
View user's profile Send private message 
PaulR

Joined: 04 May 2005
Posts: 246
Location: UK

PostPosted: Sat 14 Jun 2014, 16:24    Post subject:  

The first dozen or so lines of this page should make things clearer (at least for Vala) with regard to properties:

https://wiki.gnome.org/Projects/Vala/PropertiesSample

My understanding is that 'fields' are just class variables.

Paul.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [3 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0490s ][ Queries: 11 (0.0057s) ][ GZIP on ]