• 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

    • Whack another 1-2% tax on multinational tech giants, with those funds going directly to this. They wouldn't notice it, despite no doubt fighting like hell saying it'll bankrupt them! It also shouldn't be up to the EU to facilitate this, nor directly fund it, despite it ideally being for a social good. Open source definitely needs a heck of a lot of help. The brain drain is real, and it shows. But again, that's because people follow the money, because we've been forced into needing it so desperately.
    • Brave 1.80.124 by Razvan Serea Brave Browser is a lightning-fast, secure web browser that stands out from the competition with its focus on privacy, security, and speed. With features like HTTPS Everywhere and built-in tracker blocking, Brave keeps your online activities safe from prying eyes. Brave is one of the safest browsers on the market today. It blocks third-party data storage. It protects from browser fingerprinting. And it does all this by default. Speed - Brave is built on Chromium, the same technology that powers Google Chrome, and is optimized for speed, providing a fast and responsive browsing experience. Brave Browser also features Brave Rewards, a system that rewards users with Basic Attention Tokens (BAT) for viewing opt-in ads. This innovative system provides an alternative revenue model for content creators and a way to support the Brave community. Brave 1.80.124 changes: Updated Brave Leo in sidebar so input field is selected/focused by default when opened. (#47796) Removed hardcoded client side context limits for Brave Leo which will now be enforced server side. (#41620) Upgraded Chromium to 138.0.7204.168. (#47844) Download: Brave Browser 64-bit | 1.2 MB (Freeware) Download: Brave Browser 32-bit View: Brave Homepage | Offline Installers | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • While I support Wikipedia, and use it constantly, I don't use Mastodon, or even know what it is. The internet is currently going through a dramatic shift, and will forever be changed, for better or for worse. The fear I have is loosing resources, like Wikipedia, which while it still has its flaws, is just about the best possible site that exists. Why? Well: - It's an information resources on just about any topic, the modern day encyclopaedia - It is constantly updated, and publicly edited, with measures in place to prevent misuse - Its information and policies are not being swayed by money, as it's mostly funded independently - It's simple, low resources, and not using addictive techniques to hook you - It provides an actual free service: education, unlike most others which provide a "platform" that costs and still generally has an underlying goal of profits - No ads. Refreshing in this day and age. - No clickbait, there are still standards which are all ignored on "news" sites, even publicly funded ones as they try to compete with commercial players who at the end of the day, just want ad revenue. For all its flaws, it is the pinnacle of the internet. Even if they do decide to add an AI overview of each article at the top.. I hope Mastodon finds a way to continue in this ######ed up money crazed world.
    • I certainly hope you're right, but I put nothing past Microsoft these days. Writing Microsoft with a dollars sign used to be a joke because they charged for their software, but now they charge for their software "and" shove ads and recommended products down your throat at every turn, revert settings changes after updates, etc., so perhaps it's time to start spelling it Micro$oft again, :-p
    • Glow 25.08 by Razvan Serea Glow provides detailed reporting on every hardware component in your computer, saving you valuable time typically spent searching for CPU, motherboard, RAM, graphics card, and other stats. With Glow, all the information is conveniently presented in one clean interface, allowing you to easily access and review the comprehensive hardware details of your system. Glow provides detailed information on various system aspects, including OS, motherboard, processor, memory, graphics card, storage, network, battery, drivers, and services. The well-organized format ensures easy access to the required information. You can export all the gathered data to a plain text file, facilitating sharing with others for troubleshooting purposes. No installation needed. Just decompress the archive, launch the executable, and access computer-related information. Glow runs on Windows 11 and Windows 10 64-bit versions. Glow 25.08 release notes: What's new Glow's render engine has been improved. The program now supports high-resolution displays even on multi-monitor setups and monitors with varying DPI levels. It delivers sharp and clear visuals on 8K and higher DPI screens. The TSImageRenderer algorithm has been integrated into Glow. All visual icons in the interface are now automatically resized in a DPI-aware manner, ensuring high-resolution display quality. We know that Glow's Installed Drivers and Installed Services sections load slowly. That's why the loading algorithms have been reprogrammed into a parallel structure. Now it loads with up to 95% speed increase compared to the processor core. Glow's monitor testing tools have been reprogrammed. The Dead Pixel Test and Dynamic Color Range Test now function with improved accuracy. The Screen Overlay Tool has been redesigned, featuring theme sensitivity and new functions such as a close button. The startup engine for all Glow tools has been redeveloped, allowing for more efficient and effective management of the tools. The search engine's clear button in the "Installed Drivers", "Installed Services" and "Installed Applications" sections has been refreshed with a DPI-aware design for enhanced visibility. Icons have been added to the BIOS Update, Battery Report Generation, and Export buttons. Icons have been added to all buttons across Glow's tools. The Tab key functionality in Glow's interface has been improved, enabling more precise and stable navigation between elements. Glow's logo has been updated with a new design, offering a more elegant and modern appearance. Glow's primary colors have been redesigned within the Adobe RGB Color Space, giving the interface a more contemporary look. The About section has been reprogrammed. All social media buttons now feature icons, and the close button is DPI-aware and more prominent. Fixed Bugs Fixed an issue causing control buttons to overlap and shift position at high DPI settings. Resolved a DPI-related issue where checkmarks in the top menu distorted visually at high DPI values. Fixed a parallel processing error that caused the program to crash after clicking and closing information text in any monitor test tool. Corrected a bug in the Dynamic Color Range Tool that caused white space to appear on the right and bottom when resizing. Fixed calculation errors affecting the color scale and ratios in the Dynamic Color Range Tool. Resolved a layering issue that sometimes caused message boxes to appear behind the program window. Changes The backend code structure of Glow has been improved to a modular architecture, ensuring full compatibility and easier integration with other Türkay Software products. Tools have been moved back to the top menu. Some interface icons have been replaced to provide better visual clarity. A YouTube link has been added to the About section. Note: Always unzip the program before using it. Otherwise you may get an error. Download: Glow 25.08 | 3.1 MB (Open Source) View: Glow Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Collaborator
      fernan99 earned a badge
      Collaborator
    • Collaborator
      MikeK13 earned a badge
      Collaborator
    • One Month Later
      Alexander 001 earned a badge
      One Month Later
    • One Month Later
      Antonio Barboza earned a badge
      One Month Later
    • Week One Done
      Antonio Barboza earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      592
    2. 2
      ATLien_0
      225
    3. 3
      Michael Scrip
      167
    4. 4
      Xenon
      140
    5. 5
      +FloatingFatMan
      128
  • Tell a friend

    Love Neowin? Tell a friend!