Jump to content

Recommended Posts

Hi,

Could someone explain this code:

type
  TDataContainer = class
  public type
    TIterateAction = reference to procedure (value: integer);
  strict private
    FData: TArray<integer>;
    FIndex: integer;
  public
    constructor Create(const data: TArray<integer>);
    procedure Iterate(action: TIterateAction);
    function GetFirst(var value: integer): boolean;
    function GetNext(var value: integer): boolean;
  end;

I don't understand the role of "type" after public  and before the anonymous method type declaration?

public type

 Doesn't it require a matching "end" ?

 

Thanks

Edited by AndrewHoward

Share this post


Link to post

it's a type declaration in the class

 

it's

 

type
  TDataContainer = class
  public

   type
     TIterateAction = reference to procedure (value: integer);

  strict private
    FData: TArray<integer>;
    FIndex: integer;
  public
    constructor Create(const data: TArray<integer>);
    procedure Iterate(action: TIterateAction);
    function GetFirst(var value: integer): boolean;
    function GetNext(var value: integer): boolean;
  end;

TDataContainer.TIterateAction type

 

It's just ebarcadero who does not give a fuck to implement its own syntax to the formatter.

 

 

 

 

 

  • Thanks 1

Share this post


Link to post

Delphi supports nested types. This binds the type name TIterateAction to TDataContainer in case anybody wants to refer to it outside of TDataContainer class.

 

Usually I see nested types declared as Private, which basically means they're intended for the exclusive use of that class, as nobody outside of the class can even see them.

  • Like 1

Share this post


Link to post

OT: this always requires a knowing people (or knowing AI) to realize how to name "the weird thing you see in code" properly. The following RTFM-ing with exact naming is trivial but that initial step could be really hard.

Share this post


Link to post
On 8/7/2023 at 4:56 AM, Fr0sT.Brutal said:

OT: this always requires a knowing people (or knowing AI) to realize how to name "the weird thing you see in code" properly. The following RTFM-ing with exact naming is trivial but that initial step could be really hard.

If I understand what you're saying, I think it's a big problem that renders Google practically useless if you don't know the proper term to use, or if there even is one.  You can give a code sample to google and ask, "what is this?" and you'll probably get a bunch of gibberish that does not include what you're looking for. ChatGPT might do a better job. But if you don't know what something is called, it's hard to ask anybody anything about it. Telling someone to RTFM isn't helpful b/c they don't even know what to look for. Case in point: where can you find the entire set of % parameters that can be used in a Format statement? if you go to the Help topic for Format, it doesn't say. You have to find a link buried in commentary to bring up that info. I still don't know what they're actually called.

Share this post


Link to post
On 8/12/2023 at 12:22 PM, David Schwartz said:

I think it's a big problem that renders Google practically useless if you don't know the proper term to use, or if there even is one

Yes and the fact that some coding features are only show themselves as some non-alpha symbols complicates things. Trying to google "what ^#$& means in <language name>" does not always return relevant results.

On 8/12/2023 at 12:22 PM, David Schwartz said:

Case in point: where can you find the entire set of % parameters that can be used in a Format statement?

Hm, I was always going Format > Formatting strings for this in D7 help and XE2 already has these parameters in the function's page.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×