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 4335690
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:42:16+00:00 2026-05-21T10:42:16+00:00

I want to export content of a TQuery to a CSV file without using

  • 0

I want to export content of a TQuery to a CSV file without using a 3d part component(Delphi 7). From my knowledge this can not be accomplished with Delphi standard components.

My solution was to save the content in a StringList with a CSV format, and save it to a file.

Is there any comfortable solution?

PS:I don’t want to use JvCsvDataSet or any component. Question is: can this be accomplished only with Delphi 7 or higher standard components?

Thank you in advance!

  • 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-21T10:42:17+00:00Added an answer on May 21, 2026 at 10:42 am

    Of course it can.

    You just have to do the work to properly output the CSV content (quoting properly, handling embedded quotes and commas, etc.). You can easily write the output using TFileStream, and get the data using the TQuery.Fields and TQuery.FieldCount properly.

    I’ll leave the fancy CSV quoting and special handling to you. This will take care of the easy part:

    var
      Stream: TFileStream;
      i: Integer;
      OutLine: string;
      sTemp: string;
    begin
      Stream := TFileStream.Create('C:\Data\YourFile.csv', fmCreate);
      try
        while not Query1.Eof do
        begin
          // You'll need to add your special handling here where OutLine is built
          OutLine := '';
          for i := 0 to Query.FieldCount - 1 do
          begin
            sTemp := Query.Fields[i].AsString;
            // Special handling to sTemp here
            OutLine := OutLine + sTemp + ',';
          end;
          // Remove final unnecessary ','
          SetLength(OutLine, Length(OutLine) - 1);
          // Write line to file
          Stream.Write(OutLine[1], Length(OutLine) * SizeOf(Char));
          // Write line ending
          Stream.Write(sLineBreak, Length(sLineBreak));
          Query1.Next;
        end;
      finally
        Stream.Free;  // Saves the file
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple report that I want to export to a CSV file.
I want to export the data from a DaraGrid into an Excel file. Having
(I'm beginning in the Android dev) I want to export a file from /data/data....
I am using google reader for my RSS, i want to export all my
I want to create a Java application bundle for Mac without using Mac. According
I want to know what is the easiest way to export ALL content of
I want to export gridview to pdf by using the itextsharp library. The problem
I want to link from my project Trac page to my javadoc index.html file,
Right now I am using this to export a repeater (with multiple nested repeaters)
If all tables I want to delete from have the column gamer_id can i

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.