Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8112033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:20:07+00:00 2026-06-06T02:20:07+00:00

type TSomeRecord = Record field1: integer; field2: string; field3: boolean; End; var SomeRecord: TSomeRecord;

  • 0
type
  TSomeRecord = Record
    field1: integer;
    field2: string;
    field3: boolean;
  End;
var
  SomeRecord: TSomeRecord;
  SomeRecAr: array of TSomeRecord;

This is the most basic example of what I have and since I want to reuse SomeRecord (with certain fields remaining empty, without freeing everything some fields would be carried over when I’m reusing SomeRecord, which is obviously undesired) I am looking for a way to free all of the fields at once. I’ve started out with string[255] and used ZeroMemory(), which was fine until it started leaking memory, that was because I switched to string. I still lack the knowledge to get why, but it appears to be related to it being dynamic. I am using dynamic arrays as well, so I assume that trying ZeroMemory() on anything dynamic would result in leaks. One day wasted figuring that out. I think I solved this by using Finalize() on SomeRecord or SomeRecAr before ZeroMemory(), but I’m not sure if this is the proper approach or just me being stupid.

So the question is: how to free everything at once? does some single procedure exist at all for this that I’m not aware of?

On a different note, alternatively I would be open to suggestions how to implement these records differently to begin with, so I don’t need to make complicated attempts at freeing stuff. I’ve looked into creating records with New() and then getting rid of it Dispose(), but I have no idea what it means when a variable after a call to Dispose() is undefined, instead of nil. In addition, I don’t know what’s the difference between a variable of a certain type (SomeRecord: TSomeRecord) versus a variable pointing to a type (SomeRecord: ^TSomeRecord). I’m looking into the above issues at the moment, unless someone can explain it quickly, it might take some time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:20:09+00:00Added an answer on June 6, 2026 at 2:20 am

    Assuming you have a Delphi version that supports implementing methods on a record, you could clear a record like this:

    type
      TSomeRecord = record
        field1: integer;
        field2: string;
        field3: boolean;
        procedure Clear;
      end;
    
    procedure TSomeRecord.Clear;
    begin
      Self := Default(TSomeRecord);
    end;
    

    If your compiler doesn’t support Default then you can do the same quite simply like this:

    procedure TSomeRecord.Clear;
    const
      Default: TSomeRecord=();
    begin
      Self := Default;
    end;
    

    You might prefer to avoid mutating a value type in a method. In which case create a function that returns an empty record value, and use it with the assignment operator:

    type
      TSomeRecord = record
        // fields go here
        class function Empty: TSomeRecord; static;
      end;
    
    class function TSomeRecord.Empty: TSomeRecord;
    begin
      Result := Default(TSomeRecord);
    end;
    
    ....
    
    Value := TSomeRecord.Empty;
    

    As an aside, I cannot find any documentation reference for Default(TypeIdentifier). Does anyone know where it can be found?


    As for the second part of your question, I see no reason not to continue using records, and allocating them using dynamic arrays. Attempting to manage the lifetime yourself is much more error prone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

type TDelphiSignature=record Signature:array [0..3] of LongWord; Version:string; end; const DelphiSignature:array [0..2] of TDelphiSignature=( (Signature:($384F3D26,$B83782C2,$034224F3,$833A9B17);Version:'Delphi
type Tmyclass = class(TObject) somearray: array of TSometype FBool: Boolean; Fint: Integer; Fstr: string;
type TTest = class a: integer; end; TTest2 = class(TTest) b: integer; end; var
type myrec = record id:dWord; name:array[0..31] of WideChar; three:dword; count:dword; ShuXing:Single; ShuXing2:dword; ShuXing3:dWORD; end;
type TParent=class public member1:Integer; end; TChild=class(TParent) public member2:Integer; end; TGArray<T: TParent>=class public function test:T;
type SQLConn = val mutable private connection : string option member this.Connection with get()
Type t = typeof(bool); string typeName = t.Name; In this simple example, typeName would
Summarization: type MyObject = object end; MyRecord = record end; MyClass = class end;
type TPerson = class(TObject) name : string; constructor create(name : string); end; would trigger
What Type System Version (Compatibility Level) token can I specify in ADO.NET connection string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.