trichview.com

trichview.support




Re: SaveComponentToFile && controlname


Return to index


Author

Message

Sergey Tkachenko

Posted: 12/18/2004 21:34:38


When exporting HTML, OnSaveComponentToFile is called for all controls in the

document.

In your code, you try to get information about the current item, i.e. item

at the position of caret:

rve->GetControlInfo(rve->CurItemNo, ...);

But the current item is not necessary a control to save, and may be not even

a control at all.


Unfotrunately, this event does not have parameters specifying the control

location in the document.

You need to find it yourself.

Use this function:


bool FindControlLocation(TCustomRVData* RVData, TControl* Ctrl,

  TCustomRVData* &CtrlRVData, int &CtrlItemNo)

{

  for (int i=0; i<RVData->ItemCount; i++)

  {

    if (RVData->GetItemStyle(i)==rvsComponent &&

      ( (TRVControlItemInfo*)(RVData->GetItem(i)))->Control==Ctrl)

   {

      CtrlItemNo = i;

      CtrlRVData = RVData;

      return true;

    }

    if (RVData->GetItemStyle(i)==rvsTable)

    {

      TRVTableItemInfo*table = (TRVTableItemInfo*)(RVData->GetItem(i));

      for (int r=0; r<table->Rows->Count; r++)

        for (int c=0; c<table->Rows->Items[r]->Count; c++)

          if (table->Cells[r][c])

          {

             if (FindControlLocation(table->Cells[r][c]->GetRVData(), Ctrl,

               CtrlRVData, CtrlItemNo))

               return true;

          }

    }

  }

  return false;

}


How to use:


case rvsfHTML:


  AnsiString aName;

  TCustomRVData*CtrlRVData;

  int CtrlItemNo;

  if (!FindControlLocation(rve->RVData, (TControl*)SaveMe,  CtrlRVData,

CtrlItemNo)

    return;

  // now you can use CtrlRVData->GetControlInfo(CtrlItemNo, aName, aCtrl,

AVAlign, iTag);

  // but it's simpler:

  aName = CtrlRVData->GetItemText(CtlItemNo);

  if(SaveMe->InheritsFrom(__classid(TButton)))

  {

    OutStr = "<input type=button name=" + aName + ">";

    return;

  }

  break;






>

> Dear Sergey,

>

> I'm trying to save a TRichViewEdit to a HTML file. I've inserted some

components

> like a TEdit and TButton. In the SaveComponentToFile event I'd like to get

> the name of a control using the following code:

>

> case rvsfHTML:

>

> AnsiString aName;

> TControl *aCtrl;

> TRVVAlign AVAlign;

> int iTag;

> int iIndex;

> rve->GetControlInfo(rve->CurItemNo, aName, aCtrl, AVAlign, iTag);

>

> if(SaveMe->InheritsFrom(__classid(TButton)))

> {

> OutStr = "<input type=button name=" + aName + ">";

> return;

> }

> break;

>

> I get an error when I save the TRichViewEdit to a HTML-file. When I remove

> the "rve->GetControlInfo(rve->CurItemNo, aName, aCtrl, AVAlign, iTag);"

everything

> works correctly, only I can't get the name of the control.

>

> Is there another way to get the controlname??

>

> Thanks.

>

> Pieter E.





Powered by ABC Amber Outlook Express Converter