Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How To Convert String To Pansichar Type?

Featured Replies

Posted

How do i convert Strings to PChar type?

And how can i concatenate parts of type string with parts of type PChar and PAnsiChar?

or

How do i concatenate (put together/stick) multiple variables (in one) of type PChar?

if i use 'bla bla' in function that requires PChar it is ok, but

if i want to put together my string and for example TEMP path of my system

(GetTempPath(255,P) will give us P in PChar type that has value of temp folder location)

How to do that?

Edited by ChupaChu

You should go and ask google before you create posts here. Nobody wants you to search for an hour but you should at least try finding it by yourself.

There should be a ****load of info about Delphi strings, nothing that seriously needs to be discussed.

It's fine if you don't find anything in a reasonable time or if there's some sort of bug you can't figure out.

Not trying to be rude, this is just an advice :)

Maybe this helps:

http://www.delphibasics.co.uk/RTL.asp?Name=ShortString

Especially take a look at the 'Related Commands', I guess Concat is what you're looking for ;)

  • Author

Thanks for pointing that one out, offcourse i have searched before i ask.

It must be a bug of some kind, once it works - compiles without an error

and when you copy this code to other function it will throw an error (at

least it does on my 7.2 version).

Its CreateFile and GetSystemPath that are buggy in some way.

For example If you have this:

hFile :THandle;

Buffer: array [0 .. 4095] of Char;

temp:AnsiString;

i:Cardinal;

label finito;

begin

hFile := CreateFile('\\F:\testFile.dat', GENERIC_READ or GENERIC_WRITE,

FILE_SHARE_READ or FILE_SHARE_WRITE, NIL,

OPEN_EXISTING, FILE_ATTRIBUTE_HIDDEN, 0);

If (hFile <> INVALID_HANDLE_VALUE) Then Result := True;

Now Lets say i have a name in string type and want to concatenate it to some path:

var ss:string;

GetTempPath(i,buffer);

temp:=buffer;

ss:='\\?\' + temp + ss;

//a) now this will not work:

hFile := CreateFile(PAnsiChar(ss)), GENERIC_READ or GENERIC_WRITE, //...

// B) nor this:

hFile := CreateFile('\\?\'+temp+ss), GENERIC_READ or GENERIC_WRITE,

//c) this will work:

hFile := CreateFile(PAnsiChar('\\?\'+temp+ss)), GENERIC_READ or GENERIC_WRITE,

FILE_SHARE_READ or FILE_SHARE_WRITE, NIL,

OPEN_EXISTING, FILE_ATTRIBUTE_HIDDEN , 0);

If (hFile <> INVALID_HANDLE_VALUE) Then

begin Result := True;

CloseHandle(hFile);

// now if you copy all this to new function, declare same variables you will be suprised when you get en error message on line //c) in fact i needed to adjust it to

hFile := CreateFile(GetTempPath(i,buffer)+'myfile.dat'), GENERIC_READ or GENERIC_WRITE,... in order to get it to work, although it works now without UNC names

as GetTempPath(i,buffer) returns something like this X:\ddd\dd\s\, if i try to add '\\.\' in front of it - it just wont work - it drived me crazy.

Now i got it working somehow, but i still dont get whats wrong with it.

Regards, ChupaChu!

Edited by ChupaChu

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.