Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Draw a textbox

New Here ,
Jun 25, 2012 Jun 25, 2012

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.

TOPICS
SDK
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2012 Jun 25, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 25, 2012 Jun 25, 2012

It's right, the textEditSuite is null ! Do you know how I can use "alert" or "popup alert" for test my plugin ? Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 25, 2012 Jun 25, 2012
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines