Autor Beitrag
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Do 22.07.04 16:46 
Hallo ich habe folgenden Code mit Record:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var X:record
     x:Byte;
     y:array [1..5of Char;
     z:array of Char;
    end;
    Buf:string;
begin
 X.X:=65;
 X.Y:='12345';
 SetLength(X.Z,1);
 X.Z:='6';

 Buf:=string( X ); // Das geht nicht!
Nun brauche ich dieses Array aber unbedingt als String. Wie kriege ich es hin, dass Buf am Ende 'A123456' speichert? Ich hoffe ihr versteht, was ich meine :roll:

Danke,
maxk

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Do 22.07.04 17:02 
Hi!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
function Rec2Str(Rec:TMyRec):String;
var i:integer;
buf: array[0..SizeOf(Rec)] of char;
begin
  for i:=low(buf) to High(Buf) do
    buf[i]:=#0;
  Move(Rec,Buf,SizeOF(Rec));
  Result:=Buf;
end;


Cu,
Udontknow
maxk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Do 22.07.04 17:13 
Leider funktioniert dieser Code mit meinem dynamischen Array nicht. Buf = A12345

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Do 22.07.04 17:21 
Oh, habe das dynamische Array glatt übersehen. Dann bleibt dir nischt andres übrig, als eine Routine zu schreiben, die die Sachen manuell in einen String drückt.

Cu,
Udontknow
maxk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: Do 22.07.04 17:23 
Ich hatte gehofft, gerade diese Antwort nicht zu bekommen, da der record in meinen Code ein bisschen länger ist als der oben :wink:
Egal, es gibt auch Fragen, die beantwortet werden, wenn man erfährt, dass man sie nicht beantworten kann :D

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.