yarekGmail
asked on
delphi 2010 : Incompatible types: 'Char' and 'AnsiChar'
hello experts
I installed delphi 2010
I have big troubles, my old programs do not want to run any more: I have errors:
[DCC Error] main.pas(776): E2010 Incompatible types: 'Char' and 'AnsiChar'
And I got hundreds of the same error
1) why : what happened ?
2) How to correct it ? (without having to correct hundreds of these errors): is there any compilator directive to include ?
regards
I installed delphi 2010
I have big troubles, my old programs do not want to run any more: I have errors:
[DCC Error] main.pas(776): E2010 Incompatible types: 'Char' and 'AnsiChar'
And I got hundreds of the same error
1) why : what happened ?
2) How to correct it ? (without having to correct hundreds of these errors): is there any compilator directive to include ?
regards
Yes, that's a crucial mistake to go for Delphi 2009 without knowing that "things" changed.
You will have to keep AnsiChar only for old dll interfaces, or other low-level routines that need to fix the character on 1 byte (especially all byte arrays or buffers). Other string routines should stay as Char (which is now equivalent to WideChar) as everything in the VCL and Windows NT, XP, etc... works in Unicode strings.
You will have to keep AnsiChar only for old dll interfaces, or other low-level routines that need to fix the character on 1 byte (especially all byte arrays or buffers). Other string routines should stay as Char (which is now equivalent to WideChar) as everything in the VCL and Windows NT, XP, etc... works in Unicode strings.
Article which focusses a bit more on resolving the migration problem than complaining about the change:-
http://compaspascal.blogspot.com/2009/05/upgrading-major-project-to-delphi-2009.html
http://compaspascal.blogspot.com/2009/05/upgrading-major-project-to-delphi-2009.html
ASKER
Here is for instance some code that produces such error:
lpszSubject := PChar(Subject)
Incompatible types: 'Char' and 'AnsiChar'
regards
lpszSubject := PChar(Subject)
Incompatible types: 'Char' and 'AnsiChar'
regards
function xSendMailMAPI(const Subject, Body, FileName, SenderName, SenderEMail,
RecepientName, RecepientEMail: String) : Integer;
var
message: TMapiMessage;
lpSender,
lpRecepient: TMapiRecipDesc;
FileAttach: TMapiFileDesc;
SM: TFNMapiSendMail;
MAPIModule: HModule;
begin
try;
FillChar(message, SizeOf(message), 0);
with message do
begin
if (Subject<>'') then
begin
lpszSubject := PChar(Subject)
end;
if (Body<>'') then
begin
lpszNoteText := PChar(Body)
end;
if (SenderEMail<>'') then
begin
lpSender.ulRecipClass := MAPI_ORIG;
if (SenderName='') then
begin
lpSender.lpszName := PChar(SenderEMail)
end
else
begin
lpSender.lpszName := PChar(SenderName)
end;
lpSender.lpszAddress := PChar('SMTP:'+SenderEMail);
lpSender.ulReserved := 0;
lpSender.ulEIDSize := 0;
lpSender.lpEntryID := nil;
lpOriginator := @lpSender;
end;
if (RecepientEMail<>'') then
begin
lpRecepient.ulRecipClass := MAPI_TO;
if (RecepientName='') then
begin
lpRecepient.lpszName := PChar(RecepientEMail)
end
else
begin
lpRecepient.lpszName := PChar(RecepientName)
end;
lpRecepient.lpszAddress := PChar('SMTP:'+RecepientEMail);
lpRecepient.ulReserved := 0;
lpRecepient.ulEIDSize := 0;
lpRecepient.lpEntryID := nil;
nRecipCount := 1;
lpRecips := @lpRecepient;
end
else
begin
lpRecips := nil
end;
if (FileName='') then
begin
nFileCount := 0;
lpFiles := nil;
end
else
begin
FillChar(FileAttach, SizeOf(FileAttach), 0);
FileAttach.nPosition := Cardinal($FFFFFFFF);
FileAttach.lpszPathName := PChar(FileName);
nFileCount := 1;
lpFiles := @FileAttach;
end;
end;
MAPIModule := LoadLibrary(PChar(MAPIDLL));
if MAPIModule=0 then
begin
Result := -1
end
else
begin
try
@SM := GetProcAddress(MAPIModule, 'MAPISendMail');
if @SM<>nil then
begin
Result := SM(0, Application.Handle, message, MAPI_DIALOG or
MAPI_LOGON_UI, 0);
end
else
begin
Result := 1
end;
finally
FreeLibrary(MAPIModule);
end;
end;
if Result<>0 then
begin
MessageDlg('Error sending mail ('+IntToStr(Result)+').', mtError, [mbOk],
0)
end;
except;end;
end;
replace all String with AnsiString, and PChar with PAnsiChar, it should work with only string conversion before the function is called
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi guys,
Apologies for the delay in responding, that was due to two days of absense and the fact that
I got stuck with trying to find the reasons for my problem.
It now seems that the problems that I get are due to the unicode support of recent releases of Delphi (and Delphi 2010 that I use).
I tried the several files that you sent me, I tried to change myself all the
String=>AnsiString, Char=>AnsiChar, PChar=>PAnsiChar
and I also tried to use the {$H-} compiler directive. All of them without success.
In the particular files that you sent, in all cases the error was at line 1310 of AviWriter_2.pas, in the AVIFileOpen call:
When I step into AVIFileOpen the debugger gets me into System.pas: line 17000
in the function _UStrToPWChar(const S: UnicodeString): PWideChar;
where S = 'C:\Users\santon\Desktop\t mp.avi' is the path to the avi file. AviWriter-2.jpg
System-pas.jpg
Apologies for the delay in responding, that was due to two days of absense and the fact that
I got stuck with trying to find the reasons for my problem.
It now seems that the problems that I get are due to the unicode support of recent releases of Delphi (and Delphi 2010 that I use).
I tried the several files that you sent me, I tried to change myself all the
String=>AnsiString, Char=>AnsiChar, PChar=>PAnsiChar
and I also tried to use the {$H-} compiler directive. All of them without success.
In the particular files that you sent, in all cases the error was at line 1310 of AviWriter_2.pas, in the AVIFileOpen call:
// Open AVI file for write
AVIERR := AVIFileOpen(pfile, PChar(Workfile), OF_WRITE or OF_CREATE, nil);
//Shareexclusive causes nothing but trouble on an exception
if AVIERR <> AVIERR_OK then
raise Exception.Create('Failed to create AVI video file. Err: $' + IntToHex(AVIERR, 8));
I get a value for AVIERR=-2147221164. I have attached an image for the error message.When I step into AVIFileOpen the debugger gets me into System.pas: line 17000
in the function _UStrToPWChar(const S: UnicodeString): PWideChar;
where S = 'C:\Users\santon\Desktop\t
System-pas.jpg
Please, ignore my previous post. That was intended for a different question. Apologies...
How to fix:
No, there is no way to change from Unicode to Ansi.
You will have through your code and change it. Can you give me a line with an error so I can advise how to fix??