Proper way to retrieve data from TextField into NSString

Matthew Jew mjew at icnc.com
Thu Sep 21 19:20:31 CDT 2006


Hello,

I am using C++ VSDK 2.4.2 on Mac (both PowerPC and Intel, which is  
the core of my problem).

I have a TextField, defined this way:

	valueText = CreateTextField ( Table, "valueText" );

In this field, I store an HTML page.
(To store the data, I just use Valentina Studio. I open the HTML page  
in a text editor, select all, copy,
  then paste the text into the "valueText" field in Valentina Studio.)

My problem is how to retrieve it into an NSString.

I was doing it this way:

id	returnValue = nil;
NSMutableData	*aMutableData;
unsigned long dataLength;

I_FldBlob_Ptr pBlobField = dynamic_cast< I_FldBlob* > 
(aHTMLTemplateTable->valueText.get());
dataLength = pBlobField->get_DataSize();
aMutableData = [[NSMutableData alloc] initWithLength:dataLength];
pBlobField->ReadData( (char *) [aMutableData mutableBytes],  
dataLength );
returnValue = [[[NSString alloc] initWithData:aMutableData  
encoding:NSUnicodeStringEncoding] autorelease];
[aMutableData release];

After this, the variable "returnValue" should contain the HTML page  
in an NSString.
And it does work... on PowerPC.

However, on an Intel Mac, it does not, and I believe it is because of  
the byte-ordering problem.
(PowerPC being big-endian, Intel being little-endian.)
Do I need to go through the entire NSMutableData buffer and swap all  
the bytes myself, or
is there a better way to do this?

Am I even doing it properly in the first place?
Is there a Cocoa-based procedure that is Universal for PowerPC and  
Intel Macs?

- Matthew



More information about the Valentina mailing list