Recent

Author Topic: string concantenation problem[SOLVED]  (Read 2938 times)

jbmckim

  • Full Member
  • ***
  • Posts: 144
string concantenation problem[SOLVED]
« on: February 26, 2018, 12:43:46 am »
I'm using the following example to illustrate a problem I'm having.  The program is too large to include the full program context.  When run, 'test str' is not concatenated to the string (that line is embedded in the program and does fail).  There's no other catastrophic or other error.  InsList has 2 entries and 1 in this case is the second entry in a 0 based list.  The 0th element of InsList behaves correctly with 'test str' being properly appended.

My first hope of course is that someone says "Oh hell yes!  That happened to me and here's what you do..."  Barring that, what might I look at/be suspicious of the InsList[1].InsSerial entry?  The InsSerial is a return from an off board piece of hardware.  Something may be off there but it does work calling another device.   

Any thoughts will be appreciated.


Code: Pascal  [Select][+][-]
  1.  
  2. type
  3.   TInsList = specialize TFPGObjectList<TInstrument>;
  4.  
  5. var
  6.   InsList : TInsList;
  7.  
  8. Test := IntToStr(InsList[1].RunTimeInsNumber) + InsList[1].InsSerial + 'test str';

« Last Edit: February 26, 2018, 09:15:42 pm by jbmckim »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: string concantenation problem
« Reply #1 on: February 26, 2018, 01:39:27 am »
Try:
Code: Pascal  [Select][+][-]
  1.   Temp := Concat(s1,s2,s3);
  2.  

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: string concantenation problem
« Reply #2 on: February 26, 2018, 03:22:42 am »
The program is too large to include the full program context.
I doubt it will not fit in a attached zipfile. but ok  :)

Quote
When run, 'test str' is not concatenated to the string (that line is embedded in the program and does fail).
This description is vague at best. You did not tell what you expected and what it actually resulted into for you. So, you analyzed it is wrong, but it doesn't have to. Perhaps you made another error somewhere else in your code.

Alas, the description you have manufactured doesn't give us any clue. Better post some evidence with hard data :)

Quote
The 0th element of InsList behaves correctly with 'test str' being properly appended.
Perhaps my lack of English skills but i see the word appending and str, giving me the impression that this test str is being appended to something else. To what exactly, we have no clue as code showing that is missing.

Quote
Any thoughts will be appreciated.
I can't imagine you are unable to come up with some simplified version of your code. Or perhaps better yet, do not depend on data coming from an external piece of hardware but instead make a dummy function that returns some hard-coded values and process those. Does the error still happens then ?

If not then you found your error, if it does produce the same behaviour then show us some more code to look at.

Quote
My first hope of course is that someone says "Oh hell yes!  That happened to me and here's what you do..."
Of course but i can advise a zillion of things all that won't solve your problem. I simply miss a crystal ball to be able to pinpoint the right advise ;)

PS: or wait... i came up with a advise that makes sense for your context: step-through your code using the debugger and inspect your variables on each change

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: string concantenation problem
« Reply #3 on: February 26, 2018, 03:37:12 pm »
engkin - fails both with the '+' and with the Concat.

molly - I'll try isolating the instrument.

Bart

  • Hero Member
  • *****
  • Posts: 5288
    • Bart en Mariska's Webstek
Re: string concantenation problem
« Reply #4 on: February 26, 2018, 03:40:22 pm »
InsList[1].InsSerial maybe ends with a #0 (null chatacter).
If so, then the concatenation works, but if you try to display the string, displaying will stop at the #0.
(Pascal strings can have a null character, but you cannot display that on any OS)

Bart

jbmckim

  • Full Member
  • ***
  • Posts: 144
Re: string concantenation problem
« Reply #5 on: February 26, 2018, 09:15:14 pm »
And Bart for the win!

The driver for the devices being called seems to append a byte '0' in some cases.  When this gets converted to a string in pascal, you're pretty much done with anything after the null in that string.   I have a request into the vendor as to whether this is intended behavior.  I hope not but it could be because it seems that 7 character serial numbers are handled verbatim but odd numbered serial numbers have a null appended. 

In short, the null in a string is an issue.

I don't think the issue is limited to "display" however as I had problems using the string in areas other than display.  Specifically, calling SQLite routines.

jamie

  • Hero Member
  • *****
  • Posts: 6128
Re: string concantenation problem[SOLVED]
« Reply #6 on: February 26, 2018, 11:06:13 pm »
That is standard practice to end a string with a #0, those are C type Char strings...

Use array of characters or a block of memory to store the load, then access is via a
PChar, the string code will read it up to the #0, that is the END marker.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018