?
Solved

Exporting Delphi 7 Dataset to Text File

Posted on 2003-03-27
7
Medium Priority
?
1,750 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
5 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

569 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