?
Solved

delphi 2010  : Incompatible types: 'Char' and 'AnsiChar'

Posted on 2009-12-22
8
Medium Priority
?
11,427 Views
1 Endorsement
Last Modified: 2013-11-23
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
1
Comment
Question by:yarekGmail
8 Comments
 
LVL 3

Expert Comment

by:crumley
ID: 26109093
seriously...you didn't know that Delphi 2009+ was Unicode?? You might want to research a little more before you buy next time.

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??
0
 
LVL 25

Expert Comment

by:epasquier
ID: 26110870
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.
0
 
LVL 31

Expert Comment

by:moorhouselondon
ID: 26110871
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:yarekGmail
ID: 26111028
Here is for instance some code that produces such error:

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;

Open in new window

0
 
LVL 25

Expert Comment

by:epasquier
ID: 26111160
replace all String with AnsiString, and PChar with PAnsiChar, it should work with only string conversion before the function is called
0
 
LVL 1

Accepted Solution

by:
kjdonovan earned 2000 total points
ID: 26151130
Just going through this now.
Possible solutions include:
adding compiler directive {$H-}  to beginning of unit -no long string support.
changing string->ansiString, char to ansiChar pChar to pAnsiChar
changing built in function calls to their ansi equivalents where available eg DeleteFile-> DeleteFileA, CreateFile->CreateFileA etc.
0
 

Expert Comment

by:Stelios_Antoniou
ID: 35867219
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:

  // 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));

Open in new window

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\tmp.avi' is the path to the avi file. Error MessageAviWriter-2.jpg
System-pas.jpg
0
 

Expert Comment

by:Stelios_Antoniou
ID: 35867224
Please, ignore my previous post. That was intended for a different question. Apologies...  
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question