Populate two column table from file

Sorry to bring this up again, I know this has been covered in previous posts, but I simply cannot get it to work, so please help!

I have source data file, where the data is separated by a semi-colon (;), like this:

Printer1;Location 1
Printer2;Location 2

Now I want to populate a table in my AppleScript app that i build using Xcode 3.2.6 when I click a button.

My code looks like this and does not work (the error is “Can’t set window 1 of «class datS» “CharDataSource” to «class datS» id 5. (-10006)”)

on clicked theObject
	start progress indicator "listspinner" of window 1
	set DataSource to (POSIX file "/tmp/printerlist_test.txt")
	set CharData to (read DataSource)
	set theDataSource to make new data source at end of data sources with properties {name:"CharDataSource"}
	set data source of table view 1 of scroll view 1 of window 1 to "CharDataSource"
	tell theDataSource
		make new data column at end of data columns with properties {name:"printercolumn"}
		make new data column at end of data columns with properties {name:"locationcolumn"}
	end tell
	set {TID, text item delimiters} to {text item delimiters, ";"}
	tell data source "CharDataSource"
		repeat with a from 1 to (count (paragraphs of CharData))
			make new data row at end of data rows of theDataSource
			set data source of table view 1 of scroll view 1 of window 1 to contents of theDataSource
			set contents of data cell "printercolumn" of data row a of data source of table view 1 of scroll view 1 of window 1 to word 1 of paragraph a of CharData
		end repeat
	end tell
	set text item delimiters to TID
	stop progress indicator "listspinner" of window 1
	
end clicked

What am I doing wrong?

In the debugger console I get “Illegal NSTableView data source (CharDataSource). Must implement numberOfRowsInTableView: and tableView:objectValueForTableColumn:row:”

Hi,

there are a couple of reference errors.
For better referencing connect the tableView to the awakeFromNib handler, add a property and
assign the object reference in the awakeFromNib handler. Change the literal string “tableView” to the appropriate value.
This avoids the long “table view 1 of scroll view 1 of window 1” chain

property tableView : null

on awake from nib theObject
	if name of theObject is "tableView" then
		set tableView to theObject
	end if
end awake from nib

Then use this code


on clicked theObject
	start progress indicator "listspinner" of window 1
	set dataSource to (POSIX file "/tmp/printerlist_test.txt")
	set charData to (read dataSource)
	set theDataSource to make new data source at end of data sources with properties {name:"CharDataSource"}
	set data source of tableView to theDataSource
	tell theDataSource
		make new data column at end of data columns with properties {name:"printercolumn"}
		make new data column at end of data columns with properties {name:"locationcolumn"}
	end tell
	set {TID, text item delimiters} to {text item delimiters, ";"}
	repeat with a from 1 to (count paragraphs of charData)
		make new data row at end of data rows of theDataSource
		set contents of data cell "printercolumn" of data row a of theDataSource to text item 1 of paragraph a of charData
		set contents of data cell "locationcolumn" of data row a of theDataSource to text item 2 of paragraph a of charData
	end repeat
	set text item delimiters to TID
	stop progress indicator "listspinner" of window 1	
end clicked