Autor Beitrag
*Knust*
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 95



BeitragVerfasst: Do 09.08.07 00:11 
Moin!
Ich habe ein Problem:
Ich will über winexec ein Programm starten und muss daher den Pfad angeben. in diesem steht allerdings eine Variable und Delphi will, dass diese ein Pansichar ist.
Jetzt würde ich gerne wissen, wie man strings in pansichars umwandelt.

Ich habe Pchar(variable) und pansichar(variable) schon probiert...das funzt nich...

Was soll ich tun???
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 09.08.07 00:39 
Erstmal :welcome: hier im Forum!

Mit winexec? Äußerst schlechte Idee ;-). Das ist schon seit mindestens 10 Jahren oder so veraltet und sollte nicht mehr verwendet werden, das kommt AFAIK noch aus der 16-Bit-Zeit...

Nimm ShellExecute:
ausblenden Delphi-Quelltext
1:
ShellExecute(Handle, 'open', DieProgrammExe, '', '', SW_SHOWNORMAL);					


PChar(StringVariable) ist schon richtig, das brauchst du ggf. auch bei DieProgrammExe... Zeig doch mal deinen Code ;-).
*Knust* Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 95



BeitragVerfasst: Do 09.08.07 00:54 
Ich habs schonmal mit shellexecute versucht...aber er kennt den befehl nicht... muss ich da irgendwas bei "uses" reinschreiben?

mit freundlichen grüßen

knust
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 09.08.07 00:56 
ausblenden Delphi-Quelltext
1:
uses ShellAPI;					
*Knust* Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 95



BeitragVerfasst: Do 09.08.07 01:08 
Nö geht immernoch nich...+Pchar(programme[s])+'.cmd' ich habe die komplette zeile von dir kopiert und das als exe hingeschrieben... trotzdem sagt er mir: [Fehler] Unit1.pas(44): Inkompatible Typen: 'String' und 'PAnsiChar'

Kp wodran das liegt...
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 09.08.07 01:10 
Du musst schon den kompletten String in PChar umwandeln...
ausblenden Delphi-Quelltext
1:
PChar(programme[s] + '.cmd')					

Weil in deinem Code nimmst du ein PChar + einen String --> das ist wieder ein String, du übergibts also einen String.
*Knust* Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 95



BeitragVerfasst: Do 09.08.07 01:12 
Jawoll es geht....



DANKE!!!!

mfg


Knust
mexx2k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 60



BeitragVerfasst: Do 30.08.07 08:12 
Gibt es diese Funktion auch umgekehrt?

pChar to String ?

Danke
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 30.08.07 08:18 
Jup. Dann schreibt man einfach statt PChar ein String - und die PChar-Variable in die Klammer, nicht den String. Also alles genau umgekehrt.

_________________
We are, we were and will not be.
mexx2k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 60



BeitragVerfasst: Do 30.08.07 08:19 
jou danke... manchmal geht alles einfacher als man denkt ;)
arj
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 378

Win XP/Vista, Debian, (K)Ubuntu
Delphi 5 Prof, Delphi 7 Prof, C# (#Develop, VS 2005), Java (Eclipse), C++, QT, PHP, Python
BeitragVerfasst: Do 30.08.07 08:19 
Eigentlich neuer Thread!

Meines wissens kann man auch einfach ne Zuweisung machen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var p : PChar;
    s : string;
begin
  p := PChar('Blub');
  s := p;
mexx2k
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 60



BeitragVerfasst: Do 30.08.07 08:21 
so hatte ich es auch probiert:
das problem hierbei ist nur, wenn der pchar so aussieht: 'stringinhalt'#0#0#0#0#0#0 ;

^^
dann kopiert er die lästigen zeichen einfach mit...