Autor Beitrag
Juniorsatan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Sa 13.03.10 18:08 
Ich scheitere gerade an einem wirklich simplen Problem. Ich habe eine Zeichenkette > 255 Zeichen, möchte also Ansistring verwenden.

Irgendwas muss ich da prinzipiell falsch machen.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button4Click(Sender: TObject);
var
  zk: ansistring;
begin
zk:='3784372787845234238482394289fujkv gvjk645u68945689gv4c54v6456vg463784372787845234238482394289fujkv gvjk645u68945689gv4c54v6456vg463784372787845234238482394289fujkv gvjk645u68945689gv4c54v6456vg463784372787845234238482394289fujkv gvjk645u68945689gv4c54v6456vg463784372787845234238482394289fujkv gvjk645u68945689gv4c54v6456vg463784372787845234238482394289fujkv gvjk645u68945689gv4c54v6456vg46';
end;


führt zu "[Error] Unit1.pas(102): String literals may have at most 255 elements".

Auch wenn ich vorher ein

ausblenden Delphi-Quelltext
1:
SetLength(zk, 30000000);					


einfüge, hilft das nichts. In diversen Tutorials wird jedoch auch nichts anderes gemacht, sondern genau so, wie ich es probiere. Ich arbeite mit Delphi 7.2.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Sa 13.03.10 18:38 
Ist nen "Fehler" im Editor.
Teil das auf mehrere Zeilen auf:
ausblenden Delphi-Quelltext
1:
2:
3:
sk := 'text' + 
      'noch mehr text' + 
      'ganz viel text';

_________________
PROGRAMMER: A device for converting coffee into software.
Juniorsatan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Sa 13.03.10 19:03 
Um es mal etwas anders zu beschreiben:


Delphi kann zwar längere Strings speichern, aber nur 255 Zeichen maximal pro Befehl, richtig?
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: So 14.03.10 05:08 
Nichtmal "pro Befehl", sondern, wie die Fehlermeldung auch sagt, "pro Literal".
Also pro 'Text' in Anführungszeichen.

Deswegen kann man das auch so umgehen wie user profile iconXentar da sagte.


Weiß eigentlich jemand, warum das so ist? Ich mein, dass der TurboPascal-Compiler noch nicht, ist ja klar. Der ist ja self-sustaining, damals mit ShortStrings. Aber spätestens seit Delphi 3 sollte sich das doch erledigt haben... Irgendwie ist das schon seltsam. Genau, wie die Abwesenheit von HEREDOC, das gehört da ja mit in die Kategorie.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
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: So 14.03.10 08:45 
Ganz einfach, diese bis zu 255 Zeichen werden in der Exe vermutlich (habe ich jetzt nicht überprüft) als ShortString gespeichert, was ja auch Sinn macht, da es schnell, platzsparend und einfach ist. Hängt man dann mehrere aneinander sind das eben mehrere ShortStrings.

Ab Delphi 2009 ist dieses Limit nicht mehr vorhanden. Vermutlich ganz einfach weil Unicode möglich ist und das nicht in ShortStrings gespeichert werden kann. Jedenfalls kann man dort problemlos auch längere Strings in den Editor schreiben.
Naja, ok, bis auf Ausnahmen, es gibt da noch kleine Bugs, zumindest in D2009. :mrgreen:
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: Fr 19.03.10 21:54 
String-Literale werden als LongStrings mit RefCount=-1 in der EXE gespeichert.

_________________
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.