• 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

    • Everything's OK! 🤣🤣🤣  
    • XnView 2.52.2 by Razvan Serea XnView is freeware software that allows you to view and convert graphic files. It's very fast and easy to use. But more importantly it supports more than 500 graphics formats! Import about 500 graphic file formats Export about 50 graphic file formats Multipage TIFF, Animated GIF, Animated ICO support Image IPTC, EXIF metadata support EXIF auto rotation support IPTC editing Resize, rotate, crop support Lossless rotate & crop (jpeg) support Adjust brightness, contrast... Auto levels, contrast Modify number of colors Apply filters (blur, average, emboss, ...) Apply effects (lens, wave, ...) Fullscreen mode Slide show with effects Batch convert, batch rename Create WEB page easily Screen capture Create contact Sheet Create or edit Multi-page file (TIFF, DCX, LDF) TWAIN & WIA support (Windows only) Print support (Windows only) Drag & Drop support (Windows only) Compare image side by side Filmstrip layout 44 languages support (Windows only) XnView 2.52.2 changelog: NConvert: -xyb for JPEGli XnView vs XnView MP: XnView is the classic, lightweight version with basic features and Windows-only support. XnView MP is the modern, cross-platform version with an improved interface, better performance, and extended format support. Download: XnView 2.52.2 Installer | Standalone | ~24.0 MB (Non-commercial freeware) Download: XnView MP 1.9.2 64-bit | Standalone | ~100.0 MB Download: XnView MP 1.9.2 32-bit | Standalone | ~60.0 MB View: XnView Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Correct. You don’t buy anything that’s free (if it were).
    • Vivaldi 7.4.3684.52 by Razvan Serea Vivaldi is a cross-platform web browser built for – and with – the web. A browser based on the Blink engine (same in Chrome and Chromium) that is fast, but also a browser that is rich in functionality, highly flexible and puts the user first. A browser that is made for you. Vivaldi is produced with love by a founding team of browser pioneers, including former CEO Jon Stephenson von Tetzchner, who co-founded and led Opera Software. Vivaldi’s interface is very customizable. Vivaldi combines simplicity and fashion to create a basic, highly customizable interface that provides everything a internet user could need. The browser allows users to customize the appearance of UI elements such as background color, overall theme, address bar and tab positioning, and start pages. Vivaldi features the ability to "stack" and "tile" tabs, annotate web pages, add notes to bookmarks and much more. Vivaldi 7.4.3684.52 changelog: [Address bar] URL is searched instead of opening (VB-117198) [Chromium] Update to 136.0.7103.179 [Settings][Workspaces] Add Workspace Rule button hidden by 4th rule (VB-117181) Download: Vivaldi 64-bit | 125.0 MB (Freeware) Download: Vivaldi 32-bit | ARM64 View: Vivaldi Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Week One Done
      Wayne Robinson earned a badge
      Week One Done
    • One Month Later
      Karan Khanna earned a badge
      One Month Later
    • Week One Done
      Karan Khanna earned a badge
      Week One Done
    • First Post
      MikeK13 earned a badge
      First Post
    • Week One Done
      OHI Accounting earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      687
    2. 2
      ATLien_0
      268
    3. 3
      Michael Scrip
      202
    4. 4
      +FloatingFatMan
      169
    5. 5
      Steven P.
      142
  • Tell a friend

    Love Neowin? Tell a friend!