Categories

Senin, 11 Januari 2010

Get data from the Internet

Create a new userobject from standard class internetresult, call it n_cst_internet.

Declare this instance variable


string is_data


With that userobject type, you need to overload the internetdata function (which will be called by the PB VM automatically). The return type is integer and the parameter is data, its type is a blob.



[integer internetdata(blob data)]

is_data = string(data)
RETURN 1



NOTE : Since PB10 is unicode-based (previous version were ansi-based), you may need to specify that result contains Ansi characters and not the default Unicode encoding.



Blob lbl_data
lbl_data = Blob(data, EncodingANSI!)
is_data = String(lbl_data, EncodingANSI!)

Then from your script

integer li_rc
inet linet_main
n_cst_internet luo_data // as defined above

linet_main = CREATE inet
luo_data = CREATE n_cst_internet

SetPointer(HourGlass!)
li_rc = &
linet_main.GetURL("http://www.rgagnon.com/classes/java-io.dat", luo_data)
SetPointer(Arrow!)
IF li_rc = 1 THEN
MessageBox("Data from Real's HowTo", luo_data.is_data)
ELSE
MessageBox("Data from Real's HowTo", "Oops rc:" + string(li_rc))
END IF

DESTROY luo_data
DESTROY linet_main



POSTing data maybe a little more tricky. You may need to set all the headers.



string httprequest,ls_header
String ls_url,ls_headers
long ll_ret
long ll_length
Blob lblb_args
inet linet_main
n_cst_internet luo_data

linet_main = CREATE inet

luo_data = CREATE n_cst_internet

ls_url = "http://localhost/mypage.jsp"
lblb_args = blob("foo=bar")
ll_length = Len(lblb_args)
ls_headers = "Content-Type: " + &
"application/x-www-form-urlencoded~n" + &
"Content-Length: " + String( ll_length ) + "~n~n"
ll_ret = libet_main.PostURL(ls_url,lblb_args,ls_headers,8080,luo_data)



Since PB10 is using Unicode to encode characters, code designed with PB9 (which is Ansi) with the PostURL function may not work. The fix is simple, specify the Ansi encoding in the Blob function.


lblb_args = Blob("foo=bar", EncodingAnsi!)

Kamis, 08 Oktober 2009

How To Create Simple TableView Part 2

In this tutorial you will learn how to capture the events on clicking the rows of the table. Table isn’t just used to preset the data but it is often needed to do some action against the selection of a cell.

Here is an overview of the part 1, how Table view is created.

1) Declare the UITableView variable and map it to the actual table in interface builder.

2) Implement UITableViewDelegate and UITableViewDataSource protocols.

3) Assign delegate and data source to UITableView object.

4) Implement numberOfRowsInSection and cellForRowAtIndexPath datasource methods as follows:


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return4;

}- (UITableViewCell *)tableView:(UITableView *)ttableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
//If a cell with this identifier already created then it will be reused
UITableViewCell *cell = [ttableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (!cell) {
//If a cell with this identifier doesn't already created then it will be created and assigned an identofier
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}

// Index of the cell to be processed
int index = indexPath.row;

// Text is going to be set of the cell
cell.text = [NSStringstringWithFormat:@"%i", index];

// Cell is returned which will be shown on table
return cell;
}

Now you will learn about another method named didSelectRowAtIndexPath which is called everytime when user select a cell. You have to implement this method in the same controller class. Following is a basic implementation of this methos which will show an alert to the user saying “Row# n is selected”.

-(void)tableView: (UITableView*) ttableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Message to show. indexPath.row is the row number selected
NSString* msg = [NSStringstringWithFormat:@"Row# %i is selected", indexPath.row];
// Creating an alert view with the message above
UIAlertView *alertmsg = [[UIAlertViewalloc] initWithTitle:@"title"message:msg delegate:selfcancelButtonTitle:@"OK"otherButtonTitles:nil];
// Show the alert
[alertmsg show];
// Releae the alert
alertmsg release];
}

Now when a user will select any row an alert message will be shown. You can do in this method what ever you want according to your need. Following out put will be shown on selection of 2nd row:

Screen Shot Tableview Part 2

Hope this tutorial has helped you understanding UITableView selection event. In next Part I’ll explain the basics of creating custom cells.

Selasa, 04 Agustus 2009

Updated Android SDK is now available

Android Developers Blog author Jason Chen reports writes about the availability of the new Android SDK which is called m5-rc14. The new version will therefore be called as Android SDK m5-rc14.

Google Phone

Following are the changes to the m5-rc14 edition:

  • New user interface
  • Layout animations
  • Geo-coding
  • New media codecs
  • Updated Eclipse plug-in