Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Helfer funktioniert nicht bei statischen Record-Methoden (https://www.delphipraxis.net/185920-helfer-funktioniert-nicht-bei-statischen-record-methoden.html)

Der schöne Günther 17. Jul 2015 17:51

Delphi-Version: XE7

Helfer funktioniert nicht bei statischen Record-Methoden
 
Wie komme ich mit einem Record-Helfer an private statische Methoden des Records?

Delphi-Quellcode:
type
   TSomeRecord = record
      strict private procedure instanceMethod();
      strict private class procedure StaticMethod(); static;
   end;

   TSomeRecordHelper = record helper for TSomeRecord
      public procedure _instanceMethod();
      public class procedure _StaticMethod(); static;
   end;

   TMyObject = class(TObject)
      strict private class procedure StaticMethod(); virtual; abstract;
   end;

{ TSomeRecord }

procedure TSomeRecord.instanceMethod();
begin
   //
end;

class procedure TSomeRecord.StaticMethod();
begin
   //
end;

{ TSomeRecordHelper }

procedure TSomeRecordHelper._instanceMethod();
begin
   self.instanceMethod(); // Das klappt schonmal...
end;

class procedure TSomeRecordHelper._StaticMethod();
begin
   //self.StaticMethod(); // E2003: Undeklarierter Bezeichner "self"
   //StaticMethod(); // E2003: Undeklarierter Bezeichner "StaticMethod"
   //TSomeRecord.StaticMethod(); // E2361 Auf private-Symbol TSomeRecord.StaticMethod kann nicht zugegriffen werden
   //inherited StaticMethod(); // E2075 Diese Form des Methodenaufrufs ist nur in Methoden von abgeleiteten Typen erlaubt
   raise EProgrammerNotFound.Create('Delphi-Praxis, zu Hilfe!');
end;

Stevie 17. Jul 2015 18:46

AW: Helfer funktioniert nicht bei statischen Record-Methoden
 
Delphi-Quellcode:
type
   TSomeRecord = record
      strict private class procedure StaticMethod(); static;
   end;

   TSomeRecordHelper = record helper for TSomeRecord
      private procedure __StaticMethod(); inline;
      public class procedure _StaticMethod(); static; inline;
   end;

{ TSomeRecord }

class procedure TSomeRecord.StaticMethod();
begin
   //
end;

{ TSomeRecordHelper }

class procedure TSomeRecordHelper._StaticMethod();
var
  Self: TSomeRecord;
begin
  Self.__StaticMethod;
end;

procedure TSomeRecordHelper.__StaticMethod;
begin
  TSomeRecord.StaticMethod;
end;

Der schöne Günther 22. Jul 2015 16:18

AW: Helfer funktioniert nicht bei statischen Record-Methoden
 
Ok, tatsächlich nur so. Danke.

PS: Warum das explizite inlining?

Stevie 23. Jul 2015 00:24

AW: Helfer funktioniert nicht bei statischen Record-Methoden
 
Zitat:

Zitat von Der schöne Günther (Beitrag 1309547)
PS: Warum das explizite inlining?

Angewohnheit, ich kann unnütze Methodenaufrufe nicht leiden :)


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:11 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