audi30tdi 0 Posted January 16, 2022 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
dummzeuch 1505 Posted January 16, 2022 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
audi30tdi 0 Posted January 16, 2022 Ok, I have a code from D7 which tre[1]:=char, and tre is string. How should this be in D10?? Share this post Link to post
David Heffernan 2345 Posted January 16, 2022 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
Nigel Thomas 35 Posted January 18, 2022 I would also suggest reading "Delphi in a Unicode World" by Nick Hodges, it gives a lot of detail on how to change pre-D2009 code to D2009+. https://edn.embarcadero.com/article/38437 Share this post Link to post
Remy Lebeau 1393 Posted January 18, 2022 Also have a look at Embarcadero's Migration and Upgrade Center 1 Share this post Link to post
Remy Lebeau 1393 Posted January 18, 2022 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
Remy Lebeau 1393 Posted January 18, 2022 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. 1 Share this post Link to post
limelect 48 Posted January 18, 2022 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
David Heffernan 2345 Posted January 18, 2022 1 hour ago, limelect said: Am I correct guys? There are likely to be other errors in such a migration. It pays to understand. 1 Share this post Link to post
limelect 48 Posted January 18, 2022 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
Tom F 83 Posted January 18, 2022 This might also be helpful: https://www.joelonsoftware.com/2003/10/08/the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses/ Share this post Link to post
Ivan Yuzafatau 0 Posted January 20, 2022 See also Unicode in RAD Studio. Share this post Link to post