Page 1 of 1

strnew replacement?

Posted: Tue Feb 19, 2008 8:11 am
by toolwiz
In D2007, it says that 'strnew' is deprecated. Unfortunately, the help doesn't give any suggestions on what to replace it with.

It's used in lots of the routines here that deal with item tags.

Is there something else to use that's equivalent and not deprecated?

-David

Posted: Tue Feb 19, 2008 8:59 am
by Sergey Tkachenko
It cannot be replaced when working with TRichView tags.
Do not worry, it still works and will never be removed from Delphi, otherwise it will break a lot of existing code.

Posted: Tue Feb 19, 2008 8:51 pm
by Pieter Zijlstra
This is a little stange AFAIK StrNew is not deprecated but NewStr is. But NewStr is not used in RichView. :?

Posted: Wed Feb 20, 2008 1:19 am
by toolwiz
Pieter Zijlstra wrote:This is a little stange AFAIK StrNew is not deprecated but NewStr is. But NewStr is not used in RichView. :?
That's funny ... I'm seeing both of them used throughout RV code. (Do a Find In Files for both of 'em and it finds both.) I didn't realize there were both StrNew and NewStr. So if I use StrNew, that's ok?

-David

Posted: Wed Feb 20, 2008 6:15 am
by Sergey Tkachenko
NewStr() is never used in RichView code. But some functions have parameters named NewStr.
And yes, Pieter is right, StrNew is not deprecated. There is no reason why function allocating a new string on the heap should be deprecated.

Posted: Thu Feb 21, 2008 5:04 pm
by Pieter Zijlstra
So if I use StrNew, that's ok?
No problem and even NewStr is not a direct problem if you can live with some compiler hints (these can be switched as well).
It usually means that it will not be maintained in future versions, but also quite often that there is a (sometimes better) replacement in another unit.
Some functions are depecrated for a couple of versions now and are still present in Delphi's source code.

Posted: Thu Feb 21, 2008 5:39 pm
by toolwiz
I've run into several deprecated functions. The sad part is that it's not mentioned in the help for them, and there's no practical way to find what function should be used to replace them. (No "See Also" to similar functions.)

-David

Posted: Fri Feb 22, 2008 10:21 pm
by Pieter Zijlstra
True, most of the time I look them up in the source, usually that will give you a hint to look elsewhere or sometimes a comment why it was deprecated and what the new function is (thinking of FileAge at the moment but that one is documented in the help also).
Are you using any deprecated function/procedure at the moment?

Posted: Fri Feb 22, 2008 10:44 pm
by toolwiz
Besides this one, just a component or two in the Raize Components 4 library. But that's different.

-David

Posted: Sat Feb 23, 2008 8:46 pm
by Sergey Tkachenko
As for NewStr, it was deprecated already in Delphi2. Probably this function was useful in ancient times, when pascal had only fixed length strings.