Migracja z Delphi 7 do Delphi 2010 - "Huge strings"

0

Przenoszę projekt z Delphi 7 do Delphi 2010. Natknąłem się na następujący problem:

 
	type
		str20  = string[20];

Deklaracja procedury

 
	procedure SpaceRemove(var st : string);

Kod który generuje błąd (E2033 Types of actual and formal var parameters
must be identical)

 
	var
		s : str20;
	...
	SpaceRemove(s);

W delphi 7 problem rozwiązywały dyrektywy ({$H-},{$LONGSTRINGS OFF}) lub wyłączenie opcji kompilacji "Huge strings".
Czy istnieje rozwiązanie tego problemu bez zmiany deklaracji funkcji i typu zmiennych?**

0

Wykonałem przykład zawarty w linku i po kompilacji mam dwukrotnie wartość 4.
http://www.delphibasics.co.uk/RTL.asp?Name=$LongStrings&ExpandCode1=Yes#Ex1

0
procedure SpaceRemove(var st : string);

daj

procedure SpaceRemove(var st : ansistring);

albo jak nie zadziała

procedure SpaceRemove(var st : shortstring);
0

W miarę możliwości lepiej nie używać shortstring. Wtedy one będą domyślnie ansistring a w nowym Delphi zostaną zamienione domyślnie na unicodestring i wszystko się bardzo łatwo przekonwertuje.

0

Znalazłem takie wątki na forum:
https://forums.embarcadero.com/thread.jspa?messageID=93155&tstart=0#93155
https://forums.embarcadero.com/thread.jspa?messageID=19850&tstart=0#19850
ale srednio pomocne.

Mariusz Jędrzejowski napisał(a)

W miarę możliwości lepiej nie używać shortstring. Wtedy one będą domyślnie ansistring a w nowym Delphi zostaną zamienione domyślnie na unicodestring i wszystko się bardzo łatwo przekonwertuje.

Rozumiem ze lepszym rozwiązaniem w tej sytuacji jest zmiana typów zmiennych pozostawiając deklaracje procedur/funkcji bez zmian?

0

W miarę możliwości lepiej nie używać shortstring. Wtedy one będą domyślnie ansistring

shortstring to shortstring a nie ansistring.

0

Jeżeli shortstring pozostaje bez zmian w nowym Delphi to pewnie można tak zostawić, jednak gdyby zaszła potrzeba postawienia tu znaków unicode to można je od razu zamienić (jeśli się da) na string.

0
wyrwibronek napisał(a)

Przenoszę projekt z Delphi 7 do Delphi 2010. Natknąłem się na następujący problem:

 
	type
		str20  = string[20];

Deklaracja procedury

 
	procedure SpaceRemove(var st : string);

Kod który generuje błąd (E2033 Types of actual and formal var parameters
must be identical)

 
	var
		s : str20;
	...
	SpaceRemove(s);

W delphi 7 problem rozwiązywały dyrektywy ({$H-},{$LONGSTRINGS OFF}) lub wyłączenie opcji kompilacji "Huge strings".
Czy istnieje rozwiązanie tego problemu bez zmiany deklaracji funkcji i typu zmiennych?**

Jak dla mnie to problemem jest zła deklaracja procedury. Powinna ona wyglądać tak:

 
	procedure SpaceRemove(var st : str20);

Przecież kompilator wyraźnie mówi, że typy zmiennej podstawianej i w nagłówku funkcji muszą być identyczne, a string i string[20] to nie jest to samo.

0
{Jeśli wystąpią poniższe problemy w D2010, należy zamienić funkcje na inne odpowiedniki}

Char     //-> AnsiChar   lub WChar
PChar    //-> PAnsiChar
String   //-> AnsiString lub WideString


StrDispose(Strings[I]); //-> StrDispose(PAnsiChar(Strings[I]));
VclJpg //-> VclImg


{ Inne
In Delphi2009 (12),
type STRING = UnicodeString
UnicodeString is not the same WideString

+ In Delphi 2007 (6,7,8,9,10,11)
STRING is the same AnsiString
WideString support for Unicode.

Because any different type in old version with Delphi 2009, someone must change anything in the PAS files of the old version:

+ In package, replace VclJpg with VclImg
+ Replace WideString with string
+ Replace WideChar with Char.
You look WideCharToMultibyte, MultibyteToWideChar may be error! Because "WideChar"-->"Char"

+ Replace WChar with Char

+ Replace AnsiStrComp with StrComp
Do that with any Ansi function.
+ Find some words as "Ansi" to remove it if you need.
}


{http://chee-yang.blogspot.com/2008/10/delphi-2009-unicode.html

Suspicious typecast of %s to %s}
var
  S: AnsiString;
begin
  MessageBox(0, PChar(S), 'Error', MB_OK);
end;

//needs to be corrected to:
var
  S: AnsiString;
begin
  MessageBoxA(0, PAnsiChar(S), 'Error', MB_OK);
end;


{WideChar reduced to byte char in set expressions.  Consider using 'CharInSet' function in 'SysUtils' unit}
A in ['a', 'b']

//needs to be corrected to:
CharInSet(A, ['a', 'b'])


{Implicit string cast from 'ShortString' to 'string'}
var
 s: ShortString;
 t: string;
begin
 t := s;
end;

{To eliminate the warning, just cast the ShortString variable as String and it is compatible with both Delphi 2007 and 2009:}
var
 s: ShortString;
 t: string;
begin
 t := string(s);
end;


{Implicit string cast from 'AnsiString' to 'string'}
var
 s: AnsiString;
 t: string;
begin
 t := s;
end;

{To eliminate the warning, just cast the AnsiString variable as String and it is compatible with
both Delphi 2007 and 2009:}
var
 s: AnsiString;
 t: string;
begin
 t := string(s);
end;


{Implicit string cast with potential data loss from 'string' to 'AnsiString'}
var
 s: AnsiString;
 t: string;
begin
 s := t;
end;

{If we are very sure that t will contain only ansi string value, then we can perform
the cast as follow safely:}
var
 s: AnsiString;
 t: string;
begin
 s := AnsiString(t);
end;

1 użytkowników online, w tym zalogowanych: 0, gości: 1