Class Problem...

Here’s the issue…

Source: http://www.xojodevspot.com/demos/classobjects.xojo_binary_project

If StyledText and RTFData were Nil, an error should be raised.
To test the demo, enter some random text in the textarea, press add…enter another test “text” into the textarea and press add.

If you click entry 1 or 2 from the StyledText listbox…nothing happens…same with RTFData…but Text maintains the StyledText.Text!!! All three properties are set in the class computed StyledText property.

what is going on?! :frowning:

FYI… on OSX… only clicking on TEXT re-fills the textarea… the other two do nothing

That’s the problem dave lol…all three listboxes should re-fill the textarea :frowning:

Even worse, I use this same technique in my recently released SimDesignerCanvas. Odd part is…it works in the SDC control…but not this simple little demo!!!

Sorry… mis-read your orignal post… I thought you said it only did not work on ONE… :slight_smile: so at least we have proven I can re-create the situation… and in debugger all the parts seem to be in the right place at the right time…

But it seems I ran across something like this a while ago… intriguing :slight_smile:

StyledText is linked to the textarea. ie, when the text is cleared in the textarea, the styledtext object changes.
When you are setting the styledtext of the textfield, you are setting it to itself. (you’ve saved a reference to the object owned by the textarea rather than a copy)

The RTFValue is pulled from the StyledText object (owned by the textarea) rather than the rtfdata you saved.

The text is text and so it works.

Jim nailed it

I have two projects in front of me. Both use the same technique. One it works, one it doesn’t; Which is what led me to make this little demo, to see if there was “something else” in my code making it not work…and no, I’m not to blame :-p But why it works in one program and not the other is going to frustrate the heck out of me.

@Jim Mckey.
So when I save the RTFData as a string, shouldn’t the string still exist? Once it’s been converted from StyledText.RTFData (a string) to a string property…It should still exist yes? And StyledText is a Class of its own.

For instance:
Dim x as new StyledText
x.RTFData = “the rtf data string”
then you could apply it to a textarea as,
TextArea.StyledText = x

so technically, the class exists outside of a TextArea, can only be applied to a textarea, and should exist whether it is attached to a textarea or not (as in the dynamic creation above)…and it still doesn’t explain why RTFData, which is a string, suddenly “no longer exists.”

THATS WHAT MY ISSUE HAD BEEN!!! :slight_smile:

I had to clone the styled text into another instance First

  SUB CLONE_STYLEDTEXT(master as StyledText,ByRef Clone as StyledText)
  Dim i As Integer
  Dim sr As StyleRun
  For i=0 To master.StyleRunCount-1
    sr=New StyleRun
    sr.Bold=master.StyleRun(i).Bold
    sr.Font=master.StyleRun(i).Font
    sr.Italic=master.StyleRun(i).Italic
    sr.Size=master.StyleRun(i).size
    sr.text=master.StyleRun(i).text
    sr.TextColor=master.StyleRun(i).TextColor
    sr.Underline=master.stylerun(i).Underline
    clone.InsertStyleRun sr,i
  Next i
dim st as styled text.
st=new styledtext
clone_styledtext(textarea1.styledtext,st)

but yeah… RTF should have worked…

[quote=88325:@Matthew Combatti]So when I save the RTFData as a string, shouldn’t the string still exist? Once it’s been converted from StyledText.RTFData (a string) to a string property…It should still exist yes? And StyledText is a Class of its own.

[/quote]

Yes, but you are calling

Styles(me.ListIndex).StyledText.RTFData //the current rtf of the current state of the StyledText

rather than

Styles(me.ListIndex).RTFData //the RTF you pulled originally

Not the way this is set up :stuck_out_tongue:
The styled texts items all refer to the same single instance attached to the TextAreas - they’d need to clone it
The RTF was grabbing the data back out of the StyledText.RTFData not the saved data

ok :-p thanks guys. I actually did that in my SDC but didn’t even think about creating another dynamic instance to hold the existing instance before destroying the original in my second project. :slight_smile: