Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Delphi conversion syntax
Mon, Nov 25 2013 7:58 PMPermanent Link

Colin Wood

VirtualTec P/L

The following line of code related to the LocalConfigPath will compile but raises a warning "implicit string cast with potential data lost from TMaskedText to AnsiString".

       with FritzE2Session1 do
       begin
         SessionType          := stLocal;
         LoginPassword       := 'EDBDefault';
         LoginUser              := 'Administrator';
         LocalConfigPath     := CreateConfig1Edit.Text;
       end;

What would be the better way to write this to avoid the typecasting problem?
Thanks
Colin
Tue, Nov 26 2013 12:03 PMPermanent Link

Adam Brett

Orixa Systems

Colin

The problem is happening because of the datatype of the CreateConfig1Edit.Text property is not ANSIString, but EDB's LocalConfigPath is.

Provided that users do not type in non-ANSI characters this code will work fine.

If your users are in Russia or India and type into the text property it will explode in flames, well cause an AV at least Smile

>>What would be the better way to write this to avoid the typecasting problem?

If all your users will always be ANSI-character users you don't really need to worry about it. I have quite a few of these messages in my compiles and I ignore them.

If you want to be super safe, then you can test for the characters in the Edit being ANSI, and if they are not you can warn / stop the user.
Tue, Nov 26 2013 9:48 PMPermanent Link

Colin Wood

VirtualTec P/L

Thanks Adam, One more thing not to have to worry about is a good thing.  Currently my program is being used in Australia and New Zealand so it sounds like I'm fairly safe for the time being.
Regards
Col
Mon, Dec 2 2013 2:45 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Adam,

<< If your users are in Russia or India and type into the text property it
will explode in flames, well cause an AV at least Smile>>

It won't AV, but the user may not get the string conversion that you want,
depending upon their current system locale.

Note: this won't be an issue anymore with the next minor release and the
ANSI/Unicode property switch functionality since the EDB string properties
will always be the same type as the default string type of the
Delphi/C++Builder compiler that you're using.  The ANSI/Unicode conversion
will automatically occur in the internals of the engine.

Tim Young
Elevate Software
www.elevatesoft.com
Image