• 0

[Delphi] Problem with SaveToFile


Question

Hey guys.

I'm having a problem with my code, ok I explain me more. I have the next visual design:

RAD.thumb.png.68c7b12a0a8980e4627684910dd092e0.png 

 

In my SaveDialog button I have the next code (added on the "Exportar" button):

procedure Button2Click(Sender: TObject);
var
  i: integer;
  strT: string;
  slst: TStringList;
begin                             
  slst:= TStringList.Create;
Try     
  With DBGrid1.DataSource.DataSet Do  
  begin                              
      First;
    while not Eof do   
    begin
      strT:= '"'+Fields[0].AsString+'"';
      for i:= 1 to FieldCount-1 do
        strT:= strT+',"'+Fields[i].AsString+'"';
      slst.Add(strT);               
      Next;
    end; 
          First;    
  end;   
  if SaveDialog1.Execute(0)then 
      slst.SaveToFile(SaveDialog1.filename);
Finally         
  slst.Free;
End;   
         
end; 

And its save me only the DBGrid, but I wanna save the full file, I mean, the Columns and content of the DBGrid and the operation result (on the bottom).

Can anybody explain me how to do it or what I'm doing wrong, please?

Thanks.

Regards.

Link to comment
https://www.neowin.net/forum/topic/1397048-delphi-problem-with-savetofile/
Share on other sites

5 answers to this question

Recommended Posts

  • 1

You need to iterate though the DbSet Fields property and write out the FieldName in each field.

E.g.

  Field: TField; // in var section

  // put this before adding row values
  strT := '';
  for Field in DBGrid1.DataSource.DataSet.Fields do
    strT := '"' + Field.FieldName + '",';
  slst.Add(strT);

And you can add the value of the text box to the stringlist. 

  On 26/06/2020 at 14:36, Code Name: Lockdown said:

Wow, I didn't realise that Deplhi was still a language people used!  I always remember it being a competitor to VB6 (rightly or wrongly)

Expand  

It's more popular than you'd think. You can also use recent versions to create macOS, iOS and Android apps. 

  • Like 2
  • 0
  On 26/06/2020 at 14:36, Human.Online said:

Wow, I didn't realise that Deplhi was still a language people used!  I always remember it being a competitor to VB6 (rightly or wrongly)

Expand  

Jajaja neither do I, but the report system that I use comes with this language and I need to know how can I do solve it 😛 I tried in some ways but I can't get the full report like I need it. That's the reason why I'm using Delphi jajaja, it's not because I wanna, it's because the system comes with it jajaja.

Regards.

  • 0

I got it :) after a lot of tries jejejeje

Now I need to print the TLabel with the Memo on the bottom (Total de Período en MN: and the Memo next it)

 

RAD.thumb.png.68c7b12a0a8980e4627684910dd092e0.png 

 

I can did to print the Memo as this way:

 

  With Memo1.DataSource.DataSet Do
  begin                              
      First;
    while not Eof do   
    begin             
      strT:= '"'+Fields[0].AsString+'"';
      for i:= 1 to FieldCount-1 do
        strT:= strT+',"'+Fields[i].AsString+'"';
      slst.Add(strT);               
      Next;  
    end; 
          First;    
  end;  

But I don't know how to do it whith the Label next with the Memo.

Could you help me please?

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • RoboForm 9.7.5 by Razvan Serea RoboForm is the top-rated Password Manager and Web Form Filler that completely automates password entering and form filling. RoboForm makes logging into Web sites and filling forms faster, easier, and more secure. RoboForm memorizes and securely stores each user name and password the first time you log into a site, then automatically supplies them when you return. RoboForm's powerful Logins feature eliminates the manual steps of logging into any online account. With just one click RoboForm will navigate to a Web site, enter your username and password and click the submit button for you. Completing long registration or checkout forms is also a breeze. Simply click on your RoboForm Identity and RoboForm fills-in the entire form for you. You no longer need to remember all your passwords. You remember one Master Password, and RoboForm remembers the rest. This allows you to use stronger passwords, making your online experience more secure. RoboForm uses strong AES encryption for complete data security. The all new RoboForm comes with Chrome and Safari browser support, iPhone/iPad and Android support, as well a brand new RoboForm Everywhere license for use on unlimited computers and mobile devices. RoboForm 9.7.5 changelog: Prepared for the upcoming RoboForm browser extension with New Auth. Download: RoboForm 9.7.5 | 42.1 MB (Free, paid upgrade available) View: RoboForm Website Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • NTLite 2025.06.10460 is out.
    • I understand. I am not talking about benchmarks at all, even though I probably should look into those too - I just mean historically Vivaldi was a rather sluggish chromium browser when in use compared to other chromium browsers. I am always willing to give it additional tries whenever performance improvements are mentioned in the patch notes.
    • First make whole system slow and now making it fast. That's your own doing-undoing !!
  • Recent Achievements

    • One Year In
      Vladimir Migunov earned a badge
      One Year In
    • One Month Later
      daelos earned a badge
      One Month Later
    • Week One Done
      daelos earned a badge
      Week One Done
    • Mentor
      Karlston went up a rank
      Mentor
    • One Month Later
      EdwardFranciscoVilla earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      495
    2. 2
      snowy owl
      252
    3. 3
      +FloatingFatMan
      250
    4. 4
      ATLien_0
      225
    5. 5
      +Edouard
      181
  • Tell a friend

    Love Neowin? Tell a friend!