?
Solved

Exporting Delphi 7 Dataset to Text File

Posted on 2003-03-27
7
Medium Priority
?
1,556 Views
Last Modified: 2010-05-18
I was looking for help how to export the Dataset to Text File. Searching the WEB, I got an answer by reading the marcoszorilla's answer to Claudio, dated 01/05/2003.

Unfortunately, it was for export to excel & not to Text File. I've rewrite my program, incorporating the suggestion by marcos & it work fine for excell. Only one thing, what is HLinalbaF.disablecontrol stand for ?

Any Idea how I can export Dataset to text file !

It it possible, within a same delphi form, I could type & execute SQL commands and when I got the Dataset right, only then I will export it to TextFile.

Thank you.
 
0
Comment
Question by:Hasim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Accepted Solution

by:
wildhorselei earned 100 total points
ID: 8222567
Hi,I think u can do like this:
var
  DataSetText:TSTrings;
  ALine:strng;
begin
  DataSetText:=TStringList.Create;
  YourDataSet.First;
  With YourDataSet do
    begin
      Aline:=FieldbyName('').value;
      Aline:=Aline+FieldbyName('').value;//u can put into  yours partition
 
      ....
     DataSetText.add(Aline);
     Next;
    end;
  DataSetText.SaveTofile();
end;  
  Good Luck!
0
 
LVL 27

Assisted Solution

by:kretzschmar
kretzschmar earned 100 total points
ID: 8222757
an older app from mine (d3-bde)
but it will also work with small changes with ado and d7
(SimpleSqlExporter)

unit export_u;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Db, DBTables, Grids, DBGrids, ExtCtrls, Buttons;

type
  TSQLExport = class(TForm)
    DataSource1: TDataSource;
    Query1: TQuery;
    SaveDialog1: TSaveDialog;
    Panel1: TPanel;
    Memo1: TMemo;
    Panel2: TPanel;
    DBGrid1: TDBGrid;
    Splitter1: TSplitter;
    Panel3: TPanel;
    Splitter2: TSplitter;
    Label1: TLabel;
    Panel4: TPanel;
    Splitter3: TSplitter;
    Edit1: TEdit;
    Label2: TLabel;
    SB_Execute: TSpeedButton;
    Session1: TSession;
    ComboBox1: TComboBox;
    Label3: TLabel;
    OpenDialog1: TOpenDialog;
    SB_Load: TSpeedButton;
    SB_Save: TSpeedButton;
    SB_Export: TSpeedButton;
    procedure SB_ExecuteClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SB_ExportClick(Sender: TObject);
    procedure SB_LoadClick(Sender: TObject);
    procedure SB_SaveClick(Sender: TObject);
    procedure Splitter2Moved(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  SQLExport: TSQLExport;

implementation

{$R *.DFM}

procedure TSQLExport.SB_ExecuteClick(Sender: TObject);
var i : Integer;
begin
  if ComboBox1.Text <> '' then
  Begin
    SB_Export.enabled := False;
    query1.close;
    query1.DatabaseName := ComboBox1.Text;
    query1.sql.clear;
    for i := 0 to memo1.lines.Count - 1 do
      query1.sql.add(memo1.lines.Strings[i]);
    try
      query1.Open;
      SB_Export.enabled := True;
    except
      showmessage('Error in Statement');
    end;
  end
  else ShowMessage('Select first an Alias');
end;

procedure TSQLExport.FormCreate(Sender: TObject);
begin
  Session1.GetAliasNames(ComboBox1.Items);
end;

procedure TSQLExport.SB_ExportClick(Sender: TObject);
var
  i : Integer;
  f : textfile;
  s : String;
begin
  if Edit1.Text <> '' then
  begin
    query1.disableControls;
    if savedialog1.execute then
    begin
      assignFile(f,Savedialog1.Filename);
      try
        rewrite(F);
        query1.first;
        while not(query1.eof) do
        begin
          s := '';
          for i := 0 to query1.fieldcount - 1 do
            s := s + query1.fields[i].asstring+edit1.text;
          delete(s,Length(s),1);
          writeln(f,s);
          query1.next;
        end;
        closefile(f);
        showmessage('Export Successfull');
      except
        Showmessage('Error on saving ExportFile : '+Savedialog1.FileName);
      end;
    end;
    query1.First;
    query1.enablecontrols;
  end
  else showmessage('Input a Delimeter');
end;

procedure TSQLExport.SB_LoadClick(Sender: TObject);
begin
  If Opendialog1.Execute then
  begin
    Try
      memo1.Lines.LoadFromFile(Opendialog1.FileName);
    Except
      Showmessage('Error on Loading File : '+Opendialog1.FileName);
    end;
  end;
end;

procedure TSQLExport.SB_SaveClick(Sender: TObject);
begin
  If SaveDialog1.Execute then
  begin
    try
      Memo1.Lines.SaveToFile(Savedialog1.FileName);
    Except
      Showmessage('Error on saving File : '+Savedialog1.FileName);
    end;
  end;
end;

procedure TSQLExport.Splitter2Moved(Sender: TObject);
begin
  ComboBox1.Width := Splitter2.Left - 6;
  Label1.Left := Splitter2.Left - 28;
end;

end.

meikl ;-)
0
 
LVL 3

Expert Comment

by:marcoszorrilla
ID: 8224998
Only one thing, what is HLinalbaF.disablecontrol stand for ?

This improves the speed and avoids the blinking of the DbGrid where we are showing the Data.

Best Regards.
Marcos.



0
 

Author Comment

by:Hasim
ID: 8228909
Thank u very much to wildhorselei, kretzschmar & marcoszorrilla for assisting me in writing the code.

I've tried the suggestions with few modifications and it works fine.

Cheers
0
 

Expert Comment

by:CleanupPing
ID: 9316568
Hasim:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question