Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Re: Problems migrating from v1 to v3

Posted on 1998-02-16
3
Medium Priority
?
182 Views
Last Modified: 2010-04-04
Hi...
   I asked this question before and zitt responded with what I though would be a solution. It's only just now that I tried his suggestions and they didn't work. But I've already graded his answer and that question appears to be "closed"...I can't seem to get ahold of him again. So I'm repeting the question with his suggested answer. Hope you can help:

>(4) Error: "Incompatible types - 'String' and 'PChar'", caused
              >by this seemingly innocent piece of code:

              >deletefile(autoinput_file);

              >(autoinput_file is declared as a plain old String variable.
              >What's going on here?

              Question related to #5. See below.

              >Along that same theme, this line of code :

              >deletefile(homedir+'inpsort.txt')
              >('homedir' is a String variable)

              >..generates this error:

              >"Incompatible types: 'ShortString' and 'PChar'...Why? It was
              >fine in v1...

              OK... _ALL_ your string related code is because of one simple complier change.
              Delphi 3 (and 2?) use Windoze standard strings. I.E. Null terminated strings. Delphi
              calls these "long strings". To get rid of these problems, simply go into
              "Project/Options..." Menu. Select "Complier" tab. Then goto the "Syntax options"
              group box and de-select "Huge Strings" box. Your string problems should go away.
              You can also "isolate" segments of code with the {$H-} complier directive. No huge
              strings forces the complier into a more compatible mode.

              Hope this comments fix your problems!
              John

..Thanks for your attention to this. I hope you won't have to charge me more points since this was a question I already asked!

Cheers
  Shawn Halfpenny
  drumme59@sprint.ca
0
Comment
Question by:aztec
3 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1359368
Hi

If you declare a variable as a string, then you often need to type-cast it to a PChar.

E.g.
var
  s: string;
begin
  DeleteFile(PChar(s));
end;

Similarly, you can type-cast a PChar to a string:
(s is a string; p is a PChar.)
  s := string(p);

Is this what you are looking for?
JB

P.S.  I recommend leaving the Huge Strings option on.
0
 
LVL 5

Accepted Solution

by:
inter earned 200 total points
ID: 1359369
The problem is RESOLUTION. You want to call DeleteFile from SysUtils. However there are two other DeleteFile functions, one in Win32 and one in MAPI. So the following should solve

SysUtils.DeleteFile(homedir+'inpsort.txt');

Add sysutils to your uses clause and if you face this kind of weird error, search for multiple declerations of same function in different modules. So if you want to use win32 DeleteFile you should call Windows.DeleteFile . That is, think every DELPHI unit as a class holding several classes, variables, etc...

May this make all clear
Igor
0
 

Author Comment

by:aztec
ID: 1359370
Quite right Igor! Thank you!

Cheers
   Shawn Halfpenny
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

783 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