Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2003-09

Why is this not working? (PChar conversion)

5 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt
to Tony: Working on converting a component from Delphi 5... Given this: FComments: String; p :…
Shin The Gin wrote 18 lines
Am Freitag, 26. September 2003 09:14 schrieb Tony: > Given this: > > FComments: String; > p : PChar; > > This line compiles fine: > > p := PChar(ExtractFilename(FFileSource)); > > But this line generates an illegal type conversion: > > p := PChar(FComments); > > Any ideas? Has FComments been initialized? Just having a declaration doesn't give you a true string, does it?

It does for ansistrings.
An ansistring is guaranteed to be initially empty.

Michael.

Tony

Working on converting a component from Delphi 5...

Given this:

  FComments: String;
  p : PChar;

This line compiles fine:

  p := PChar(ExtractFilename(FFileSource));

But this line generates an illegal type conversion:

  p := PChar(FComments);

Any ideas?

Tony Maro Systems Consultant The Maro Group (256) 337-5759 http://www.maro.net/
Tony
to Tony
Michael Van Canneyt wrote 15 lines
On Fri, 26 Sep 2003, Tony wrote: >But this line generates an illegal type conversion: > > p := PChar(FComments); > >Any ideas? > > Is FComments an ansistring or a shortstring, IOW, did you use {$H+} ? Michael.

You guys are so smart! ;-) (in other words I'm stoopid sometimes.) Thanks! I knew that {$H+} and {$mode delphi} should be there but in porting the unit never added them.

Thanks,

-Tony