Autor Beitrag
smepal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win XP, Linux Mandbrake,SUSE 10.1, SUSE 9 PE, DEBIAN, Win 2000 Pro, Win XP Pro
Delphi
BeitragVerfasst: Di 25.10.05 20:42 
Kann mir einer mal helfen
bei mir funzt die umwandlung nit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var wide: PWidechar;
begin
if savedialog1.execute then
begin
StringToWideChar(savedialog1.filename,Wide,Sizeof(Wide));
(Webbrowser1.Document as IPersistFile).Save(Wide,false);
end;
end;

Was mache ich falsch??? wenn ich speichern will kommt folgender fehler:
Zugriffsverletzung bei Adresse 77E5A875 in Modul 'kernel32.dll' Schreiben von adresse 0046D020
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Di 25.10.05 20:50 
PWideChar ist, wie der Name vermuten lässt ein Pointer auf einen WideChar. Das heißt du musst dem Pointer erstmal eine Adresse zuweisen

Alstar
smepal Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win XP, Linux Mandbrake,SUSE 10.1, SUSE 9 PE, DEBIAN, Win 2000 Pro, Win XP Pro
Delphi
BeitragVerfasst: Di 25.10.05 20:56 
sorry aber wie geht das könnte mir das mal einer als fertigen code schreiben???
wie kann ich dem pointer eine adresse zuweisen???
smepal Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win XP, Linux Mandbrake,SUSE 10.1, SUSE 9 PE, DEBIAN, Win 2000 Pro, Win XP Pro
Delphi
BeitragVerfasst: Mi 26.10.05 14:46 
so hab das problem inzwischen gelöst
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var wide: Pwidechar;
    msg: String;
begin
string := 'baslldsldlsld';
GetMem(wide, Length(Msg) * SizeOf(WideChar) + 1);
StringToWideChar(Msg, wide, Length(Msg) * SizeOf(WideChar) + 1);
(Webbrowser1.Document as IPersistFile).Save(wide,false);
end;
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mi 26.10.05 15:06 
Wieso nicht so?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
 S: WideString;
begin
  S := 'baslldsldlsld';
  // Zugriff auf Stringdaten via "PWideChar(S)"
end;
smepal Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win XP, Linux Mandbrake,SUSE 10.1, SUSE 9 PE, DEBIAN, Win 2000 Pro, Win XP Pro
Delphi
BeitragVerfasst: Sa 29.10.05 12:52 
wenn du einen string hast den du so abtippst geht das ja auch aber nicht wenn du es zum Beispiel so machen willst
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var wide: Pwidechar;
    msg: String;
begin
string := opendialog1.filename;
GetMem(wide, Length(Msg) * SizeOf(WideChar) + 1);
StringToWideChar(Msg, wide, Length(Msg) * SizeOf(WideChar) + 1);
(Webbrowser1.Document as IPersistFile).Save(wide,false);
end;
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Sa 29.10.05 19:05 
Auch in diesem Fall kann man die eingebaute WideString brauchen. Die Konversion geschieht automatisch.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
var
 S: WideString;
begin
  S := OpenDialog1.FileName;
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: So 30.10.05 10:48 
Hallo,

eine kleine Anmerkung zu getmem dabei.
Ein WideString hat als Abschluss ein #0#0 und nicht nur ein #0
statt
ausblenden Delphi-Quelltext
1:
GetMem(wide, Length(Msg) * SizeOf(WideChar) + 1);					

lieber
ausblenden Delphi-Quelltext
1:
GetMem(wide, Length(Msg) * (SizeOf(WideChar) + 1));					

vielleicht allgemeiner
ausblenden Delphi-Quelltext
1:
GetMem(wide, Length(Msg) * (SizeOf(wide^) + 1));					


Gruss Horst

P.S.:
Nachfolgend delphifan hat natuerlich recht.


Zuletzt bearbeitet von Horst_H am So 30.10.05 15:19, insgesamt 1-mal bearbeitet
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 30.10.05 12:44 
user profile iconHorst_H hat folgendes geschrieben:
GetMem(wide, Length(Msg) * SizeOf(WideChar) + 1);

Du meintest wohl
GetMem(wide, (Length(Msg)+1) * SizeOf(WideChar));

Ausserdem ist die Verwendung von WideString zu bevorzugen, da hier leere Strings direkt als nil behandelt werden.
smepal Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win XP, Linux Mandbrake,SUSE 10.1, SUSE 9 PE, DEBIAN, Win 2000 Pro, Win XP Pro
Delphi
BeitragVerfasst: So 30.10.05 19:48 
ging nur leider in diesem fall nicht da die save funktion ein pwidechar benötigt
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 30.10.05 20:09 
user profile iconsmepal hat folgendes geschrieben:
ging nur leider in diesem fall nicht da die save funktion ein pwidechar benötigt

Doch. Vorausgesetzt du hast eine neuere Delphi-Version, kannst du's - wie schon oben geschrieben - ohne explizite Konversion machen.
Der kleine Umweg über WideString ist jedoch nötig, da PWideChar() nur castet (oder nil setzt) und nicht konvertiert.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
 Msg: WideString;
begin
  Msg := OpenDialog1.FileName;
  (Webbrowser1.Document as IPersistFile).Save(PWideChar(Msg),false);
end;

Übrigens: Nach GetMem gehört unbedingt ein Ressourcenschutzblock mit FreeMem hin.