Autor Beitrag
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Sa 17.05.08 09:56 
Hi,

ich verwende diese Komponente, um den seriellen Port anzusteuern. habe jetzt folgendes:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Timer1Timer(Sender: TObject);
var P:  ^String; S: String;
begin
 P:=@S;
 Comm.Read(P,1);
 Memo1.Lines.Add(P^);
end;

so funktioniert das aber nicht. Auch das schreiben will nicht funktionieren, es kommt zwar was an, aber ein ganz andres Zeichen. Ich bin mir sicher, dass das ein ganz banales Problem ist, aber ich hab noch nie was mit Pointern gemacht. Ich vermute mal, dass Comm.Read keinen String-Pointer erwartet :nixweiss:

Danke für eventuelle Hilfe,
Xion

[Edit] Der oben gezeigt Code wirft eine AccessViolation, sobald es ein Zeichen empfängt (empfangen sollte).

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 17.05.08 10:05 
Versuch es mal mit PChar

_________________
Markus Kinzler.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 17.05.08 10:14 
1. Bitte erst Speicher reservieren, bevor hier irgendwas rumgepointert wird :mahn:

2. PChar auf erstes Zeichen des Strings und mit diesem dann Lesen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Timer1Timer(Sender: TObject);
var P:  PChar; S: String;
begin
    SetLength(S, 1);
    P:=@S[1];
    Comm.Read(P^,1);
    Memo1.Lines.Add(S);
end;


Tipp: Strenge Typenprüfung angewöhnen ;-)

BTW: Geht alternativ auch so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Timer1Timer(Sender: TObject);
var S: String;
begin
    SetLength(S, 1);
    Comm.Read(S[1],1);
    Memo1.Lines.Add(S);
end;

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Xion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Sa 17.05.08 10:20 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Timer1Timer(Sender: TObject);
var S: String;
begin
    SetLength(S, 1);
    Comm.Read(@S[1],1);
    Memo1.Lines.Add(S);
end;

so muss es heißen ;) danke :)

*dumm anstellt* irgendwie schreibt er allerdings immer, wenn er nichts neues bekommt, das alte wieder hin *wunder*

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 17.05.08 10:26 
ausblenden Delphi-Quelltext
1:
2:
    SetLength(S, 1);
    P:=s;

_________________
Markus Kinzler.
Xion Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Sa 17.05.08 10:28 
user profile iconmkinzler hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
    SetLength(S, 1);
    P:=s;


aaah, aso, auf 1 setzen...habs auf 0 gestetzt, ging nicht :P

Danke :D

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)