Author Topic: Dictionary Xrecord text CR removed on round trip  (Read 1850 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Dictionary Xrecord text CR removed on round trip
« on: July 30, 2018, 02:42:16 PM »
Consider the following:
I have a text file that has ANSI encoding and I read it into a string in c#
Code - C#: [Select]
  1. string data = FileSystem.ReadAllText(fn);

I don't do anything to the text except embed it into the drawing as dictionary data in an Xrecord
Code - C#: [Select]
  1. ResultBuffer rb = new ResultBuffer(new TypedValue(DxfCode.Text, data));
  2. Xrecord xr = new Xrecord();
  3. xr.Data = rb;
  4. acDict.SetAt(layout.handle, xr);
  5. acTrans.AddNewlyCreatedDBObject(xr, true);
  6. acTrans.Commit();

This works fine ... however when retrieving it and exporting it to a file it isn't formatted as it is in the source file.

Code - C#: [Select]
  1. foreach (TypedValue tv in xr.Data)
  2. {
  3.     if (tv.TypedCode == DxfCode.Text)
  4.     {
  5.         data = tv.Value.ToString();
  6.     }
  7. }

So one of three things is happening
1) The CR isn't written to the Xrecord;
2) The CR isn't read from the Xrecord;
3) Something else?


To complicate things more, when I read the data into a textbox control, it shows correctly and can be copied and pasted to notepad correctly, but when saved it does not work.

I've investigated the WriteAllText function by opening a file and writing it to a temporary file and it works fine.

I'll entertain ideas  ... I could certainly parse the string and replace lf with crlf, but that just feels like a bug waiting to happen
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Dictionary Xrecord text CR removed on round trip
« Reply #1 on: July 30, 2018, 05:30:02 PM »
Well damn .. according to the MS website, it is the control that strips all CRs from the text.

I guess its a replace function after all ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Atook

  • Swamp Rat
  • Posts: 1029
  • AKA Tim
Re: Dictionary Xrecord text CR removed on round trip
« Reply #2 on: July 30, 2018, 06:25:38 PM »
Good to know Keith, thanks for the follow up.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Dictionary Xrecord text CR removed on round trip
« Reply #3 on: July 31, 2018, 12:56:59 AM »
If someone could figure out how to get the proper extended styles on the control, it could possibly be resolved.

According to MS if you set the SES_XLTCRCRLFTOCR flag it will not strip the CRLF, but I tried a dozen times and different ways to SendMessage that flag and it always fails.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

MickD

  • King Gator
  • Posts: 3636
  • (x-in)->[process]->(y-out) ... simples!
Re: Dictionary Xrecord text CR removed on round trip
« Reply #4 on: July 31, 2018, 03:15:52 AM »
have you tried using a RichTextBox control? These are designed for multiline text and reading/writing to/from file isn't a prolem AFAIK, cheers.
"Programming is really just the mundane aspect of expressing a solution to a problem."
- John Carmack

"Short cuts make long delays,' argued Pippin.”
- J.R.R. Tolkien

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Dictionary Xrecord text CR removed on round trip
« Reply #5 on: July 31, 2018, 12:21:17 PM »
Yep ... same issue
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie