Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   FPC Kompatibilitätsfrage (https://www.delphipraxis.net/209369-fpc-kompatibilitaetsfrage.html)

TurboMagic 27. Nov 2021 11:07

FPC Kompatibilitätsfrage
 
Hallo,

ein Forumsmitglied hat ja dankenswerterweise dafür gesorgt, dass DEC (https://github.com/MHumm/DelphiEncryptionCompendium)
auch FPC kompatibel ist. Ich habe FPC nicht installiert, versuche aber diese Kompatibilität zu bewahren.

Jetzt ist der Plan mit DEC 6.5 Delphi 10.1 Berlin statt bisher D2009 als minimale Version vorauszusetzen,
damit man neuere Syntax etc. benutzen kann.

Die Frage ist nun, welche der folgenden Konstrukte FPC kompatibel sind oder nicht und was man ggf. beachten muss:

1. Vordefinierte Class Helper wie .ToString/.ToInteger
2. Array operationen wie Verketten mittels +, Delete oder COpy auf Arrays (Seit Delphi XE7)
3. Neuen Syntax für Inline Initialisierung von Arrays:

Delphi-Quellcode:
var
  ba : TBytes;
begin
  SetLength(ba, 3);
  ba := [1, 2, 3];
Grüße
TurboMagic

mjustin 27. Nov 2021 11:43

AW: FPC Kompatibilitätsfrage
 
Zu class helper Einschränkungen siehe https://www.freepascal.org/docs-html/ref/refse65.html:

Zitat:

Destructors or class destructors are not allowed.
Class constructors are not allowed.
Class helpers cannot descend from record helpers, and cannot extend record types.
Field definitions are not allowed. Neither are class fields.
Properties that refer to a field are not allowed. This is in fact a consequence of the previous item.
Abstract methods are not allowed.
Virtual methods of the class cannot be overridden. They can be hidden by giving them the same name or they can be overloaded using the overload directive.
Unlike for regular procedures or methods, the overload specifier must be explicitly used when overloading methods from a class in a class helper. If overload is not used, the extended type’s method is hidden by the helper method (as for regular classes).
TObject enthält eine ToString methode. ToInteger ist nur twas für bestimmte (numerische) Typen sinnvoll, welche konkreten Fälle sind denn gesucht?

Array Operatoren werden hier beschrieben: https://www.freepascal.org/docs-html/ref/refsu48.html

Beispiel:
Delphi-Quellcode:
var
  a,b, c : array of byte;

begin
  a:=[0,1,2];
  b:=[3,4,5];
  c:=a+b;
  writeln('C has ',length(c),' elements');
Ausgabe:

Zitat:

C has 6 elements

TurboMagic 27. Nov 2021 12:30

AW: FPC Kompatibilitätsfrage
 
Danke schon mal für die Hinweise.
Naja, ToInteger ist z. B. für strings sinnvoll:

Delphi-Quellcode:
var
  s : string;
  i : Integer;
begin
  s := '5'; // oder Benutzereingabe irgendwoher...
  i := s.ToString;
  // und dann weitere Verarbeitung von i.
Grüße
TurboMagic

mjustin 27. Nov 2021 15:43

AW: FPC Kompatibilitätsfrage
 
Zitat:

Zitat von TurboMagic (Beitrag 1498305)
Danke schon mal für die Hinweise.

TStringHelper für Free Pascal

https://www.freepascal.org/docs-html...inghelper.html

Enthält unter anderem auch ToInteger (als class function)

Delphi-Quellcode:
var
  S: string;

begin
  S := '42';
  writeln(S.ToInteger);
Ausgabe:

Delphi-Quellcode:
42


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:48 Uhr.

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