Forum > Beginners

How to prevent automate assign of PChar to String

<< < (2/4) > >>

ASerge:

--- Quote from: Okoba on February 23, 2024, 09:19:30 pm ---For now, FPC automatically set a PChar to a String value and I want to disallow it for safety. Is there a way?

--- End quote ---
{$MODE TP}

PascalDragon:

--- Quote from: Okoba on February 23, 2024, 09:19:30 pm ---For now, FPC automatically set a PChar to a String value and I want to disallow it for safety. Is there a way?
--- End quote ---

No, there is not. Also there isn't anything dangerous about assinging a PChar to a String. What would be “dangerous” would be the other way around, because when you change the String variable you'd also change the PChar value which might not be desired.

marcov:
(not every pointer to char is necessarily 0-terminated)

PascalDragon:

--- Quote from: marcov on February 23, 2024, 11:10:42 pm ---(not every pointer to char is necessarily 0-terminated)

--- End quote ---

Okay, I'll grant you that 😅

Okoba:
Exactly what marcov said. And Some times, I have PChar that is part of another string, so not dangerous but creates problems, so I prefer disallowing it together

@ASerge thank you. I wished I could use TP mode for this.

@PascalDragon is not a mode switch for it to use the error just like TP mode does it? If not, is it okay to make an issue about it?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version