Autor Beitrag
Lsm09
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP, Win 7, Win 8
Turbo Delphi, Delphi 5, Lazarus
BeitragVerfasst: Sa 08.01.11 21:26 
Hallo,
ich habe folgendes Problem:
Wenn ich folgendes eingebe
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var s: string;
begin
S:= '/C net send 192.168.178.10 ' + edn.text;
if Radiobutton1.Checked = true then

ShellExecute(Application.Handle, 'open''cmd', S, nil, SW_HIDE);
end;

kommt heraus:
E2010 Inkompatible Typen: 'string' und 'PAnsiChar'
Wie behebe ich das?

Lsm09


Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am So 09.01.2011 um 00:14
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: Sa 08.01.11 21:28 
ausblenden Delphi-Quelltext
1:
PChar(S)					
Lsm09 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP, Win 7, Win 8
Turbo Delphi, Delphi 5, Lazarus
BeitragVerfasst: So 09.01.11 13:37 
??
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 09.01.11 13:42 
Du musst S nach PChar casten.
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: So 09.01.11 13:48 
Ok, mal die Erklärbär-Version:

Du hast S als String vorliegen. Das ist in Delphi ein eigener Datentyp, der nach bestimmten Spezifikationen aufgebaut ist. Blöderweise ist aber ShellExecute keine Funktion die Delphi mitbringt, sondern eine die von der WinAPI kommt, also vom Betriebssystem. Und diese Routine will keinen String übergeben haben sondern einen Pointer auf eine Zeichenkette, genannt PChar. Damit wir jetzt einen String umwandeln können, schreiben wir einfach PChar und dahinter in klammer das unseren Variablennamen bzw unseren String selbst. Dadurch bekommt ShellExecute nicht mehr den String sondern einen PChar, weil wir den String ja zuerst umgewandelt haben.

Also schreibst zu einfach in ShellExecute statt dem S ein PChar(S) hin und alles ist gut.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.

Für diesen Beitrag haben gedankt: Lsm09
Lsm09 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38

Win XP, Win 7, Win 8
Turbo Delphi, Delphi 5, Lazarus
BeitragVerfasst: So 09.01.11 14:20 
DANKE!!!
hat mir sehr geholfen!!

Programm läuft!

Lsm09