Copy link to clipboard
Copied
Hello ! I need to write one object in a document, I'm using the "getting-started.pdf" documentation for adobe SDK InDesign, in 45 page I write it code about insert using "textEditSuite->InsertText(WideString(resultString))" but not works, my InDesign not includes anything. I test using only textEditSuite->InsertText(WideString("test")) but it crashs and close indesign.
My code is:
void WFPDialogController::ApplyDialogFields(IActiveContext* myContext, const WidgetID& widgetId)
{
// TODO add code that gathers widget values and applies them.
//Get selected text of DropDownList.
PMString resultString;
resultString = this->GetTextControlData(kWFPDropDownListWidgetID); // Look up string and replace.
resultString.Translate();
// Get the editbox list widget string.
PMString editBoxString = this->GetTextControlData(kWFPTextEditBoxWidgetID);
PMString moneySign(kWFPStaticTextKey);
moneySign.Translate();
resultString.Append('\t'); // Append tab code.
resultString.Append(moneySign);
resultString.Append(editBoxString);
resultString.Append('\r'); // Append return code.
InterfacePtr<ITextEditSuite> textEditSuite (
myContext->GetContextSelection(), UseDefaultIID());
// InterfacePtr<ISpreadList> iSpreadList(iDocument, UseDefaultIID());
// if (textEditSuite && textEditSuite->CanEditText()) {
//
// ErrorCode status = textEditSuite->InsertText(WideString(resultString));
// ASSERT_MSG(status == kSuccess, "WFPDialogController::ApplyFields: can't insert text");
//
// }
textEditSuite->InsertText(WideString("teste"));
SystemBeep();
}
How I can insert correctly ?
Thanks.
Copy link to clipboard
Copied
The problem of crashing seems to be caused because you might be working on a null pointer. The code snippet you pasted above has a recipe for disaster
The following line in your code is not checking if the requested InterfacePtr obtained is null or not, and after this line you are calling a method on your InterfacePtr.
InterfacePtr<ITextEditSuite> textEditSuite (myContext->GetContextSelection(), UseDefaultIID());
In case if this InterfacePtr comes out to be null, the line following it would result in a certain crash.
So always make it a point to check the interfaceptr for validness before using it. Indesign sample codebase is filled with the preferred way to do it using a do while loop or you could raise exceptions in your code for that matter in this situation.
Make this change in your code and see if your crash still happens.
Manan Joshi
- Efficient InDesign Solutions -
MetaDesign Solutions
http://metadesignsolutions.com/services/indesign-development.php
Copy link to clipboard
Copied
It's right, the textEditSuite is null ! Do you know how I can use "alert" or "popup alert" for test my plugin ? Thanks
Copy link to clipboard
Copied
You mean you want to print the text you extract from the textbox in a alert? If this is your requirement then you can use the "InformationAlert" method of CAlert.
For ex you could use, CAlert::InformationAlert(resultString)
Manan Joshi
- Efficient InDesign Solutions -
MetaDesign Solutions
http://metadesignsolutions.com/services/indesign-development.php
Find more inspiration, events, and resources on the new Adobe Community
Explore Now