Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi string[]-Problem (https://www.delphipraxis.net/63829-string%5B%5D-problem.html)

konda 23. Feb 2006 14:11


string[]-Problem
 
Hallo,
ich will einen String ungefähr so zusammen bauen: :coder:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var wort: string[5];
begin
  wort[1]:= 'h';
  wort[2]:= 'a';
  wort[3]:= 'l';
  wort[4]:= 'l';
  wort[5]:= 'o';
  label1.Caption:= wort;
end;
Wenn ich nun aber das Programm teste, zeigt das Label nichts an. Was mache ich falsch? :?:

3_of_8 23. Feb 2006 14:14

Re: string[]-Problem
 
Probiers mal so:

Delphi-Quellcode:
var wort: string[5];
begin
  wort[1]:= 'h';
  wort[2]:= 'a';
  wort[3]:= 'l';
  wort[4]:= 'l';
  wort[5]:= 'o';
  label1.SetTextBuf(nil);
  label1.SetTextBuf(@wort[1]);
end;

Grishnak 23. Feb 2006 14:15

Re: string[]-Problem
 
[edit]gelöscht, weil Unsinn![/edit]

kingflo 23. Feb 2006 14:15

Re: string[]-Problem
 
wie er zeigt bei dir nichts an?

Wenn ich die procedure so benutze ist label1.caption hallol÷

Matze 23. Feb 2006 14:16

Re: string[]-Problem
 
Wenn du string[6] nimmst, dann geht's. Aber frag mich bitte nicht wieso, vielleicht muss ans Ende, wie beim Char etwas angehängt werden. :oops:

Die Muhkuh 23. Feb 2006 14:16

Re: string[]-Problem
 
Zitat:

Zitat von Grishnak
Delphi-Quellcode:
SetLength(wort, 5);
Sonst hat der String immer noch die Länge 0 und deine Zuweisungen schreiben irgendwo in den Speicher!

IMHO hat er mit string[5] schon eine fixe Länge und braucht kein SetLength.

[edit] Was für ein Sinn hat das eigentlich? [/edit]

Grishnak 23. Feb 2006 14:21

Re: string[]-Problem
 
in wort[0] muss die momentan genutze Länge stehen (als "char")=> "wort[0]:=#5;"

konda 23. Feb 2006 14:31

Re: string[]-Problem
 
Zitat:

Zitat von Matze
Wenn du string[6] nimmst, dann geht's. Aber frag mich bitte nicht wieso, vielleicht muss ans Ende, wie beim Char etwas angehängt werden. :oops:

Das funktioniert! Danke. :thumb:

Delphi-Quellcode:
 in wort[0] muss die momentan genutze Länge stehen (als "char")=> "wort[0]:=#5;"
[edit]So funktionierts ebenfalls![/edit]

3_of_8 23. Feb 2006 14:53

Re: string[]-Problem
 
Mit meiner Methode (siehe oben) gehts auch.

konda 23. Feb 2006 15:51

Re: string[]-Problem
 
Zitat:

Zitat von 3_of_8
Mit meiner Methode (siehe oben) gehts auch.

Bei mir kommt dann aber raus: 'hallo|' :|


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:59 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz