Delphi 7 to Delphi 2009 conversion

Hello group,
What do I need to do to comile the following code in D2009.
Compiler error after the Else
E2010: Incompatible Types 'AnsiChar' and 'Char'

  if isUnicode then
   SearchHandle :=  FindFirstFilew( PWideChar( fn ), FindDataW )
  else
    SearchHandle := FindFirstFile( PAnsiChar( Ansistring( fn ) ), 
FindDataA );
        <<<<<compiler error in the above line >>>>>>>>>>>

Regards,
Bryan
0
Bryan
4/21/2010 8:14:25 PM
📁 embarcadero.delphi.win32
📃 2183 articles.
⭐ 0 followers.

💬 2 Replies
👁️‍🗨️ 2454 Views

> What do I need to do to comile the following code in D2009.
> Compiler error after the Else
> E2010: Incompatible Types 'AnsiChar' and 'Char'
> 
>  if isUnicode then
>   SearchHandle :=  FindFirstFilew( PWideChar( fn ), FindDataW )
>  else
>   SearchHandle := FindFirstFile( PAnsiChar( Ansistring( fn ) ),
> FindDataA );        <<<<<compiler error in the above line >>>>>>>>>>>

Why on earth are you doing this? Just use

SearchHandle :=  FindFirstFile( PChar( fn ), FindData)

and you will compile perfectly across both D7 and D2009, assuming
FindData is declared as the generic TWin32FindData too.

-- 
Chris Rolliston
http://delphihaven.wordpress.com/
0
Chris
4/21/2010 9:33:19 PM
Thanks for your help!
Bryan

"Chris Rolliston" <spam@gmail.com> wrote in message 
news:236333@forums.embarcadero.com...
>> What do I need to do to comile the following code in D2009.
>> Compiler error after the Else
>> E2010: Incompatible Types 'AnsiChar' and 'Char'
>>
>>  if isUnicode then
>>   SearchHandle :=  FindFirstFilew( PWideChar( fn ), FindDataW )
>>  else
>>   SearchHandle := FindFirstFile( PAnsiChar( Ansistring( fn ) ),
>> FindDataA );        <<<<<compiler error in the above line >>>>>>>>>>>
>
> Why on earth are you doing this? Just use
>
> SearchHandle :=  FindFirstFile( PChar( fn ), FindData)
>
> and you will compile perfectly across both D7 and D2009, assuming
> FindData is declared as the generic TWin32FindData too.
>
> -- 
> Chris Rolliston
> http://delphihaven.wordpress.com/
0
Bryan
4/22/2010 1:20:48 PM
Reply: