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

  • Home
  • SEARCH
  • 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 6721777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:22:09+00:00 2026-05-26T09:22:09+00:00

D2010, Win7 64bit. Hello, I have a buttonClick event with needs to process a

  • 0

D2010, Win7 64bit.
Hello,

I have a buttonClick event with needs to process a TDataSet opened in another routine…
GetDBGenericData.

The function GetDBGenericData returns a TDataSet. This routine basically takes a tQuery component, sets it’s SQL property, and opens it. It then returns the TDataSet to my buttonclick.

procedure TForm1.Button2Click(Sender: TObject);
var
DS : TDataSet;
begin

DS := TDataSet.Create(nil);
DS := GetDBGenericData(dbSOURCE, 'LIST_ALL_SCHEMAS', [] );

while Not DS.EOF do
   begin
   ShowMessage(DS.FieldByName('USERNAME').AsString);
   DS.Next;
   end;

DS.Close;
DS.Free;

My problem is — Understanding DS.
I am creating it here in this routine. I am “assigning” it to a TDataSet that points to a component. If I DON’T Free it, I have a memory leak (as reported by EurekaLog).
If I do free it, I get an AV the next time I run this routine. (specifically inside the GetDBGenericData routine).

What I think is happening is that DS is getting assigned to (as opposed to copying) to the TDataSet that is being returned, so in effect, I am FREEING BOTH DS in this routine, and the tQuery in GetDBGenericData, when I do a free.

How do I “break” the linkage, and then delete the memory associated to ONLY the one I am dynamically creating.

Thanks,
GS

  • 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-05-26T09:22:10+00:00Added an answer on May 26, 2026 at 9:22 am

    If your DS variable is being assigned another TDataSet by GetDBGenericData, you should neither Create or Free it. You’re just using it to refer to an existing dataset.

    procedure TForm1.Button2Click(Sender: TObject);
    var
      DS : TDataSet;
      UserNameField: TField;  // Minor change for efficiency
    begin
      DS := GetDBGenericData(dbSOURCE, 'LIST_ALL_SCHEMAS', [] );
    
      // Call FieldByName only once; no need to create or
      // free this either.
      UserNameField := DS.FieldByName('USERNAME');
    
      while not DS.Eof do
      begin
        ShowMessage(UserNameField.AsString);
        DS.Next;
      end;
    
      // I'd probably remove the `Close` unless the function call
      // above specifically opened it before returning it.
      DS.Close;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have been using this function in Delphi 2006, but now with D2010
I'm converting a D2006 program to D2010. I have a value stored in a
I want to specify a project to be opened when I launch Delphi(D2010). Is
I have (in D2010) a TDrawGrid on my form. Im handling my OnDrawCell, OnSetEditText,
I know in D2010 they have added support for static constructors and destructors. Where
Is there any Delphi D2010 function like PosEx that finds a sub-string inside a
Possible Duplicate: Embarcadero D2010 hide welcome page I have Delphi 2010. How do I
Is there any comparable function like Pos that is not case-sensitive in D2010 (unicode)?
I have some code that compiles fine with D7 but fails with D2010. Obviously
Using D2010, I'd like to do something like this: procedure SizeArray(var aArr: array of

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.