Getting string value from Text field: my 2.5 code stopped working

Matthew Jew mjew at icnc.com
Thu May 15 18:51:07 CDT 2008


On May 14, 2008, at 11:34 AM, Ruslan Zasukhin wrote:

> On 5/14/08 8:44 PM, "Matthew Jew" <mjew at icnc.com> wrote:
>
> Hi Matthew,
>
>> (This is another version 2.5.8 to 3.5.2 issue).
>>
>> I have for years been using this code to retrieve my long text values
>> from my TextFields:
>>
>> I_FldBlob_Ptr pBlobField = dynamic_cast< I_FldBlob* >
>> (aHTMLTemplateTable->valueText.get());
>
>> dataLength = pBlobField->get_DataSize();
>> aMutableData = [[NSMutableData alloc] initWithLength:dataLength];
>>
>> Const_I_Value_Ptr myStringValue = aHTMLTemplateTable->valueText-
>>> get_Value();
>> unsigned long myStringLength = myStringValue->get_Length();
>> myStringValue->get_String( (unichar *) [aMutableData mutableBytes],
>> dataLength );
>>
>> returnValue = [NSString stringWithCharacters: (const unichar *)
>> [aMutableData mutableBytes] length:myStringLength ];
>>
>>
>> Although this compiles, now my application gets a EXC_BAD_ACCESS
>> error on the get_DataSize() call.
>>
>> Is there a new way to do this?
>
> Please try this line
>
>  I_FldBlob_Ptr pBlobField = QI( aHTMLTemplateTable->valueText,  
> I_FldBlob );
>
>
> QI is short cut for QueryInterface(), method good known in the COM.
>
> This is kind of dynamic_cast<>, but based on COM mechanims.
> We do not use try COM, we use its ideas
>
>
> -- 
> Best regards,
>
> Ruslan Zasukhin

Another follow up:

While the above fix worked for the quoted line, there are a few other  
cases
where a dynamic_cast was used, but in a different way:

When adding:

FBL::I_ValueDate_Ptr pvd = fbl_dynamic_cast<I_ValueDate> 
( anArticleTable->date->get_Value(forAdd) );
pvd->put_Date( year, month, day );
FBL::I_ValueTime_Ptr pvt = fbl_dynamic_cast<I_ValueTime> 
( anArticleTable->time->get_Value(forAdd) );
pvt->put_Time( hour, minute, second, 0 );


Working with date values:

Const_I_Value_Ptr pv = anArticleTable->date->get_Value();
Const_I_ValueDateTime_Ptr pvdt = fbl_dynamic_cast<const  
I_ValueDateTime>( pv );


Working with a binary field:

FBL::Const_I_ValueBinary_Ptr pvfb = fbl_dynamic_cast<const  
I_ValueBinary>( anArticleTable->fingerPrint->get_Value() );
pvfb->get_Data( (uchar*) fpBuffer, kBytesInFingerPrint );
[aPVArticle setFingerPrint: (FingerPrint *) fpBuffer];

Getting a field pointer:

I_FldString_Ptr	pStringField = fbl_dynamic_cast<I_FldString> 
( anArticleTable->subjectByWordsUpper );

Updating:

I_ValueDateTime_Ptr pvdt1 = fbl_dynamic_cast<I_ValueDateTime> 
( aNewsgroupTable->lastTimeIndexed->get_Value( forUpdate ) );
pvdt1->put_DateTime( nowDateTimeRec.year, nowDateTimeRec.month,  
nowDateTimeRec.day, nowDateTimeRec.hour, nowDateTimeRec.minute,  
nowDateTimeRec.second, 0 );

It does not seem clear to me how I would accomplish the equivalent  
functionality,
especially in the "forAdd" and "forUpdte" cases.

- Matthew





More information about the Valentina mailing list