Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi StrCopy Problem (string und pchar) (https://www.delphipraxis.net/73313-strcopy-problem-string-und-pchar.html)

Hybrid666 15. Jul 2006 15:34


StrCopy Problem (string und pchar)
 
ich hab folgendes problem:

Delphi-Quellcode:
strcopy(data,'blablabla');
funktioniert...aber ich will statt nem vordefiniertem string ne variable des typs string einfügen...aber

Delphi-Quellcode:
strcopy(data,text);
funktioniert nicht...wie kann ich das machen? (data ist ein PChar)

MfG Hybrid666

Balu der Bär 15. Jul 2006 15:37

Re: StrCopy Problem (string und pchar)
 
Ich nehme an text ist ein String?

Einfach so:
Delphi-Quellcode:
strcopy(data,PChar(text));

Klaus01 15. Jul 2006 15:40

Re: StrCopy Problem (string und pchar)
 
oder mit StrPas PChar nach String wandeln

aus der Hilfe:

Zitat:

Converts null-terminated string to a Pascal string.

Unit

SysUtils

Category

backward compatibility routines

function StrPas(const Str: PChar): string;

Description

This function is provided for backwards compatibility only. To convert a null terminated string to a Pascal-type string, use a typecast or an assignment.


Grüße
Klaus

Balu der Bär 15. Jul 2006 15:41

Re: StrCopy Problem (string und pchar)
 
strcopy erwartet aber zwei AnsiChars als Übergabewerte, er braucht also nichts in einen String umwandeln. ;)

3_of_8 15. Jul 2006 15:44

Re: StrCopy Problem (string und pchar)
 
Ich weiß nicht, welche Version du benutzt, aber bei mir (Delphi 7) ist StrPas deprecated.

Delphi unterstützt bei meiner Version einen impliziten Cast von PChar auf String. Umgekehrt gehts mit @str[1] oder PChar(str).

Hybrid666 15. Jul 2006 15:53

Re: StrCopy Problem (string und pchar)
 
Zitat:

Zitat von 3_of_8
Ich weiß nicht, welche Version du benutzt, aber bei mir (Delphi 7) ist StrPas deprecated.

Delphi unterstützt bei meiner Version einen impliziten Cast von PChar auf String. Umgekehrt gehts mit @str[1] oder PChar(str).

also: text ist ein string
data ist ein PChar, den ich auch als PChar brauche, weil er fest in einer function ist

Delphi-Quellcode:
function antilock( mWnd: hWnd; aWnd: hWnd; Data: PChar; Parms: PChar; Show: Boolean; NoPause: Boolean ): Integer; export; stdcall;
so...und wenn ich strcopy mit einem FESTEN string (also 'blablabla') nehme gehts, also müsste es auch gehen wenn ich da text reintu....oder ich muss eben irgendwie text zuerst in einen PChar umwandeln falls das geht...

MfG Hybrid666

P.S.: Ich nutze Delphi 6 Personal

Balu der Bär 15. Jul 2006 15:55

Re: StrCopy Problem (string und pchar)
 
Zitat:

also müsste es auch gehen wenn ich da text reintu....oder ich muss eben irgendwie text zuerst in einen PChar umwandeln falls das geht...
Hast du meinen Post gelesen? :roll:

Delphi-Quellcode:
strcopy(data,PChar(text));

3_of_8 15. Jul 2006 15:56

Re: StrCopy Problem (string und pchar)
 
Oooder strcopy(data, @text[1]);

(Ich mag diese Möglichkeit lieber, denn ich liiiebe kryptischen Code)

Hybrid666 15. Jul 2006 16:08

Re: StrCopy Problem (string und pchar)
 
ich hab das prob gelöst:

Delphi-Quellcode:
strcopy(data,PChar(text));
Danke an alle.

MfG Hybrid666

Hawkeye219 15. Jul 2006 16:11

Re: StrCopy Problem (string und pchar)
 
Hallo Manuel,

Zitat:

Zitat von 3_of_8
Oooder strcopy(data, @text[1]);

(Ich mag diese Möglichkeit lieber, denn ich liiiebe kryptischen Code)

Magst du auch den Delphi-Debugger? Den wirst du sehen, falls die Variable text einen Leerstring enthält.

Gruß Hawkeye


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:55 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz