Copied Filemaker text field text crashes Xojo

Just an observation, not something I am looking to solve because it’s not that important.

When I copy text from a text field from a Filemaker project into a textfield in Xojo and hit the Update to db button, Xojo crashes. I tried this with other apps on my Mac and with the web browser and none of them gives a problem, only when pasting text that came from Filemaker text fields. Is fm maybe adding extra code or something that Xojo cannot digest?

Just wondering.

Fire the Apple Script Editor application and copy/paste:

return clipboard info

You will get the Clipboard information about its contents like:
{{«class utf8», 5}, {«class ut16», 12}, {string, 5}, {Unicode text, 10}}

Returns different information
return the clipboard as «class RTF »

From the fm copied text I get this back:
{{string, 1881}, {Unicode text, 3762}, {«class FMcs», 0}, {«class RTF », 2045}, {«class ut16», 3764}, {«class FMcs», 0}}

not sure how to read this though.

Text copied from text created in Xojo return this:
{{«class RTF », 457}, {«class utf8», 54}, {«class ut16», 110}, {string, 54}, {Unicode text, 108}}

Do you use prepared statement in your update function? If not, some of the text styling informations FileMaker is invisible copying to clipboard, may be the cause of the crash.

1 Like

I have to admit that I don’t, I am reading up on this since some days because it is advised a lot lately to use it. I however did a lot of copy paste before when I started building the Xojo app and never had crashes.

will give you more hints…

Change “class RTF » to each of the returned classes.
Look for ut16 (it have 2 bytes more than Unicode text; Unicode Text size is twice String…

I hope you use DesktopTextFields (this will avoid to paste the RTF data. Because DesktopTextField reject Styles, chances are it filter some unwanted data.

If you are not using prepared statements and have taken no steps to clean your data, then if the text you are pasting contains a single-quote (') your app will have a big problem.

There is not much to read regarding prepared statements, it’s really very simple. Consider this UPDATE:

Var sql as string, db as SQLiteDatabase

// Assume db is open at this point

sql = "update mytable set mycol=?1 where id=?2"
db.ExecuteSQL (sql, myvar1, myvar2)

then when the program runs, placeholder ?1 is replaced by myvar1 and placeholder ?2 is replaced by myvar2. And it will work whatever is in those variables.

1 Like

I created this code, following the one I already had. Is this a correct syntax? It updates correctly to the database and the Copy/Paste error from Filemaker crash is gone.

db.ExecuteSQL("UPDATE Stories SET Story_Notes = ? WHERE ID = ?", TextAreaStoryNotes.Text, StoryID_Selected)

Yes. You can either say ? or ?1, ?2, etc. Without the numeral after the ?, the parameters in the ExecuteSQL have to be in the same order as the ? in the sql. With the numeral, ?x refers to the x’th parameter in the list of parameters.

Great, thanks! I also noticed that the Slider object now works more smoothly when updating the font size in these fields, although maybe I’m adjust imagining I :slight_smile: .

It may have do to with how FM is encoding end of line and end of string.

1 Like

Until someone paste the strings here with an hex representation, we will not know.

2 Likes

When you say Xojo crashes, you probably mean your app crashes.

Do you get an Unhandled Exception message ? If so, add some code to Unhandled Exceptions to grab information about the exception and also check the stack trace to get hints at was is wrong. This is great tool for a detective !

When you copy something in Filemaker in can tend to use an internal format. I believe something similar to JSON. That could be causing your problem.

Absolutely. But It may be XML. A function is provided to remove all the formatting in order tp get the cleaned string. Internally, FileMaker uses XML a lot.

Thanks. yes, it was the app that was crashing. The problem is solved now after changing the TextArea fields to a DesktopTextArea field and changed the UPDATE sql code to the prepared statement format.

One more questions about copying and pasting text into a text field from another source. I have the font properties for text fields set to system with size 0. How can I apply this to pasted text immediately? I noticed that when restarting the app, the pasted text does have the correct system font and 0 size, but it would be nice to see that immediately after pasting it in to the text field.