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 Fri 24 Oct 2014, 17:35
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 Posts_count  
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:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


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