• 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

    • "The company has recently announced the forming of a new agentic AI team to develop an agentic AI framework for use in robotics." I wonder if any of their executives attented, "Microsoft Build 2025" last month?
    • Microsoft Build conference to leave Seattle after years in the city by Pradeep Viswanathan Microsoft Build is a flagship annual developer conference held by Microsoft since 2011. In 2017, Microsoft relocated Build from San Francisco to its home turf in Seattle. The proximity to its main campus allowed greater participation from its own engineers and executives, offering attendees a more integrated experience. Today, Jonathan Choe revealed on X that Microsoft has decided to move its Build developer conference out of Seattle. He discovered this information via an email sent by Visit Seattle to its members. Visit Seattle is a private, non-profit destination marketing organization that promotes travel to Seattle and King County. As a result of the move, Seattle-based hotels could lose approximately 9,314 room nights annually. Surprisingly, Visit Seattle’s message included several details about Microsoft’s reasons for the change. The primary reason appears to have come from within Microsoft itself. The company feels that Build lost momentum post-COVID, and the scheduling conflict with Google I/O, a competing event, has made it harder to attract the intended audience. Microsoft’s leadership believes they can better re-energize the program and boost attendance by moving it out of Seattle. The note even suggests that Build will likely be relocated to San Francisco or Las Vegas in 2026. Another factor contributing to the decision is the condition of the city. Last month, during the conference, Microsoft leadership and attendees walked between the Hyatt Regency and the Arch building on 8th Street. Reportedly, there were complaints about the general uncleanliness of the area, the visible presence of individuals using drugs, and unhoused individuals in a recurring tent in the Arch Tunnel. Visit Seattle believes these concerns also played a role in Microsoft’s final decision to relocate Build. Given Microsoft's high-profile presence and the economic impact of the event, this relocation may spark a political storm within the Seattle mayor’s office, drawing criticism over the city’s handling of downtown conditions.
    • This is very exciting, happy to see it come back to RC.
    • What did you have to do for that? Are the steps similar to W10?
  • Recent Achievements

    • Week One Done
      daelos earned a badge
      Week One Done
    • One Month Later
      daelos earned a badge
      One Month Later
    • Mentor
      Karlston went up a rank
      Mentor
    • One Month Later
      EdwardFranciscoVilla earned a badge
      One Month Later
    • One Month Later
      MoyaM earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      491
    2. 2
      snowy owl
      252
    3. 3
      +FloatingFatMan
      251
    4. 4
      ATLien_0
      216
    5. 5
      +Edouard
      160
  • Tell a friend

    Love Neowin? Tell a friend!