Thema: FreePascal Code kürzen

Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.152 Beiträge
 
Delphi 12 Athens
 
#2

AW: Code kürzen

  Alt 10. Nov 2022, 15:31
"kürzer"?
ist verboten.
https://quality.embarcadero.com/browse/RSP-39825



Nja, im Delphi
Frag mich nicht was das "Böse" alles wie kann.


Delphi-Quellcode:
//var Autos: array of array of string;
//var Autos: array of TArray<string>;
var Autos: TArray<TArray<string>>;
Es könnte alles sehr kurz werden, wenn es so Einiges geben täte
for var Line in TFile.ReadAllLines(Application.ExePath + 'ListAllAutos.txt') do Autos[] := Line.Split(';');

https://quality.embarcadero.com/brow...0%22exepath%22
und xxx[] := yyy; oder xxx += yyy; als Shortcut für xxx := xxx + [yyy]; , so wie es fast jede andere Sprache kennt.


OK, inzwischen gibt es einige string-like Operatoren auch für Arrays.
Delphi-Quellcode:
var AllLines := TFile.ReadAllLines(ExtractFilePath(ParamStr(0)) + 'ListAllAutos.txt');
for var Line in AllLines do begin
  Autos := Autos + [AllLines[i].Split(';')];
Delphi-Quellcode:
var AllLines := TFile.ReadAllLines(ExtractFilePath(ParamStr(0)) + 'ListAllAutos.txt');
SetLength(Autos, Length(AllLines));
for var i := 0 to High(AllLines) do begin
  Autos[i] := AllLines[i].Split(';');
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu (10. Nov 2022 um 15:38 Uhr)
  Mit Zitat antworten Zitat