Jump to content
audi30tdi

Tries to convert from D7 to D10

Recommended Posts

Hello!

 

Have been using D7 for ages, but now I will try to convert it to D10, but it keeps giving me errors.

In one dproj I got this error;

[dcc32 Error] Tall_edit.pas(27): E2037 Declaration of 'KeyPress' differs from previous declaration
[dcc32 Warning] Tall_edit.pas(107): W1050 WideChar reduced to byte char in set expressions.  Consider using 'CharInSet' function in 'SysUtils' unit.
[dcc32 Warning] Tall_edit.pas(179): W1057 Implicit string cast from 'ShortString' to 'string'
[dcc32 Error] Tall_edit.pas(209): E2033 Types of actual and formal var parameters must be identical

 

I guess it is that D10 is using different code then D7, but is there a way of finding out what is wrong, and what to change code into??

 

Regards

Kåre!

 

Share this post


Link to post

The the first one is probably because key press is declared with an AnsiChar parameter.

The others are warnings. Everything boils down to string in Delphi 10 being WideString and the Char being WideChar, while in Delphi 7 these are AnsiString and AnsiChar respectively. This changed between Delphi 2007 and 2009.

Share this post


Link to post

This is all about the Unicode changes introduced 12 years ago in Delphi 2009. There are hundreds of posts about this. You aren't going to master this in minutes and with quick post here. You'll need to research this in depth. Start with Marco Cantù's Unicode whitepaper. 

Share this post


Link to post
On 1/16/2022 at 9:37 AM, dummzeuch said:

Everything boils down to string in Delphi 10 being WideString

UnicodeString, not WideString.  They are two different string types.

Share this post


Link to post
On 1/16/2022 at 9:23 AM, audi30tdi said:

Have been using D7 for ages, but now I will try to convert it to D10, but it keeps giving me errors.

It is difficult to explain what needs to be changed exactly, when you have not shown the actual code that is erroring.  However...

On 1/16/2022 at 9:23 AM, audi30tdi said:

[dcc32 Error] Tall_edit.pas(27): E2037 Declaration of 'KeyPress' differs from previous declaration

Make sure your handler/override is using the general-purpose Char type, and not using AnsiChar directly.

On 1/16/2022 at 9:23 AM, audi30tdi said:

[dcc32 Warning] Tall_edit.pas(107): W1050 WideChar reduced to byte char in set expressions.  Consider using 'CharInSet' function in 'SysUtils' unit.

Prior to Delphi 2009, Char was an alias for AnsiChar, and as such it only supported 255 values max, which is also the max number of values that that a Set supports.  Since Delphi 2009, Char is now an alias for WideChar, so it is too large to use in a Set.  If you try, the Char value has to be truncated from 16 bits to 8 bits, which is what the warning is about.  The CharInSet() function was introduced to hide that warning, but not the truncation.

On 1/16/2022 at 9:23 AM, audi30tdi said:

[dcc32 Warning] Tall_edit.pas(179): W1057 Implicit string cast from 'ShortString' to 'string

Prior to Delphi 2009, string was an alias for AnsiString. Now, it is an alias for UnicodeString.  ShortString is a fixed-length ANSI string, always has been, and still is.  Assigning a ShortString to an AnsiString is a loss-less operation, but assigning a ShortString to a UnicodeString can potentially cause data loss.  So, the compiler now requires an explicit typecast whenever you assign an ANSI string to a Unicode string, or vice versa, indicating that you understand the risk.  You really shouldn't be using ShortString for anything other than interacting with external legacy systems.

On 1/16/2022 at 9:23 AM, audi30tdi said:

[dcc32 Error] Tall_edit.pas(209): E2033 Types of actual and formal var parameters must be identical

This means your code is declaring function parameters that do not match what the compiler is expecting.  This is most commonly seen in event handlers that are using the wrong parameter types.

  • Like 1

Share this post


Link to post

It is much simpler than everybody suggestion (sorry)

I guess on key pres comes from a component (edit?)

1. Keep the source section on keypress.

2. Delete on the component where the onkeypress points.

3.. press it again it will point to a new location

4. move your old source to the new with changes if needed

 

Am I correct guys?

 

Share this post


Link to post
1 hour ago, limelect said:

Am I correct guys?

There are likely to be other errors in such a migration. It pays to understand. 

  • Like 1

Share this post


Link to post
32 minutes ago, David Heffernan said:

There are likely to be other errors in such a migration. It pays to understand. 

May be but this is the easiest way. I used this technic many many times

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×