Solved

Re: Problems migrating from v1 to v3

Posted on 1998-02-16
3
165 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 50 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now