AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Projekte .csv Datei einlesen, analysieren und bearbeitet abspeichern.
Thema durchsuchen
Ansicht
Themen-Optionen

.csv Datei einlesen, analysieren und bearbeitet abspeichern.

Ein Thema von Dade · begonnen am 18. Apr 2015 · letzter Beitrag vom 4. Mai 2015
 
Dade

Registriert seit: 18. Apr 2015
20 Beiträge
 
#7

AW: .csv Datei einlesen, analysieren und bearbeitet abspeichern.

  Alt 18. Apr 2015, 22:26
Oh,
ja, also ich nutze: Delphi XE7 und bekam diese Fehler:


[dcc32 Error] Unit1.pas(28): E2029 Statement expected but 'USES' found
[dcc32 Error] Unit1.pas(29): E2003 Undeclared identifier: 'FileCtrl'
[dcc32 Error] Unit1.pas(31): E2070 Unknown directive: 'GetFiles'
[dcc32 Warning] Unit1.pas(33): W1002 Symbol 'faArchive' is specific to a platform
[dcc32 Warning] Unit1.pas(33): W1002 Symbol 'faHidden' is specific to a platform
[dcc32 Warning] Unit1.pas(33): W1002 Symbol 'faSysFile' is specific to a platform
[dcc32 Error] Unit1.pas(37): E2003 Undeclared identifier: 'Path'
[dcc32 Error] Unit1.pas(37): E2250 There is no overloaded version of 'IncludeTrailingBackslash' that can be called with these arguments
[dcc32 Warning] Unit1.pas(37): W1002 Symbol 'IncludeTrailingBackslash' is specific to a platform
[dcc32 Error] Unit1.pas(39): E2003 Undeclared identifier: 'ExtMask'
[dcc32 Error] Unit1.pas(39): E2008 Incompatible types
[dcc32 Error] Unit1.pas(41): E2010 Incompatible types: 'string' and 'Integer'
[dcc32 Error] Unit1.pas(43): E2250 There is no overloaded version of 'SameText' that can be called with these arguments
[dcc32 Error] Unit1.pas(44): E2003 Undeclared identifier: 'List'
[dcc32 Error] Unit1.pas(46): E2003 Undeclared identifier: 'SysUtils'
[dcc32 Error] Unit1.pas(49): E2070 Unknown directive: 'TForm1'
[dcc32 Error] Unit1.pas(60): E2003 Undeclared identifier: 'SelectDirectory'
[dcc32 Error] Unit1.pas(60): E2003 Undeclared identifier: 'sdAllowCreate'
[dcc32 Error] Unit1.pas(60): E2003 Undeclared identifier: 'sdPerformCreate'
[dcc32 Error] Unit1.pas(60): E2003 Undeclared identifier: 'sdPrompt'
[dcc32 Error] Unit1.pas(68): E2003 Undeclared identifier: 'GetFiles'
[dcc32 Error] Unit1.pas(80): E2003 Undeclared identifier: 'SaveDialog1'
[dcc32 Error] Unit1.pas(83): E2003 Undeclared identifier: 'Execute'
[dcc32 Error] Unit1.pas(88): E2003 Undeclared identifier: 'FileName'
[dcc32 Error] Unit1.pas(88): E2250 There is no overloaded version of 'ChangeFileExt' that can be called with these arguments
[dcc32 Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'


Damit bekomme ich bestimmt keine .exe.


So habe ich deinen Code eingesetzt in das Fenster, das kommt, wenn ich einen tbutton einfüge und diesen doppelt anklicke:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
uses
  FileCtrl;

procedure GetFiles(Path, ExtMask: String; List: TStrings);
const
  Attrib = faArchive or faReadOnly or faHidden or faSysFile;
var
  SR: TSearchRec;
begin
  Path := IncludeTrailingBackslash(Path);

  while Copy(ExtMask, 1, 1) = '.do Delete(ExtMask, 1, 1);

  if FindFirst(Path + '*.' + ExtMask, Attrib, SR) = 0 then
  repeat
    if SameText('.' + ExtMask, ExtractFileExt(SR.Name)) then
      List.Add(Path + SR.Name);
  until FindNext(SR) <> 0;
  SysUtils.FindClose(SR);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  VorneZeilenIgnorieren,
  HintenZeilenIgnorieren,
  i, k: Integer;
  Dir, OutPath: String;
  slDateiListe, slGrosseCsv, slEinzelCsv, slTemp: TStringList;
begin
  VorneZeilenIgnorieren := 0; //2;
  HintenZeilenIgnorieren := 0; //5;

  if not SelectDirectory(Dir, [sdAllowCreate, sdPerformCreate, sdPrompt], 0) then
  begin
    MessageDlg('Kein Ordner ausgewählt.', mtError, [mbOk], 0);
    Exit;
  end;

  slDateiListe := TStringList.Create;
  try
    GetFiles(Dir, 'csv', slDateiListe);

    if slDateiListe.Count = 0 then
    begin
      MessageDlg('Kein Dateien gefunden.', mtError, [mbOk], 0);
      Exit;
    end
    else
      if MessageDlg(Format('%d CSV-Dateien gefunden. Weitermachen?', [slDateiListe.Count]),
        mtConfirmation, [mbYes, mbNo], 0) = mrNo then
          Exit;

    with SaveDialog1 do
    begin
      //Filter := 'CSV-Dateien|*.csv';
      if not Execute then
      begin
        MessageDlg('Vorgang Abgebrochen.', mtError, [mbOk], 0);
        Exit;
      end;
      OutPath := ChangeFileExt(FileName, '.csv');
      if FileExists(OutPath) then
        if MessageDlg('Datei bereits vorhanden. Überschreiben?.',
          mtConfirmation, [mbYes, mbNo], 0) = mrNo then
            Exit;;
    end;

    slGrosseCsv := TStringList.Create;
    try
      for i := 0 to slDateiListe.Count - 1 do
      begin
        slEinzelCsv := TStringList.Create;
        try
          slEinzelCsv.LoadFromFile(slDateiListe[i]);

          //In den csv-Dateien stimmt was nicht, zumindest kommt StringList
          //damit nicht klar. Schnelle Lösung. Es gibt fehlermeldungen, die
          //werden aber ignoriert.
          slTemp := TStringList.Create;
          try
            for k := 0 to slEinzelCsv.Capacity - 1 do
            try
              if Length(slEinzelCsv[k]) > 0 then
              slTemp.Add(slEinzelCsv[k]);
            except
              //Fehler Ignorieren
            end;
            slEinzelCsv.Text := slTemp.Text;
          finally
            slTemp.Free;
          end;

          //Entfernt vorne Zeilen, wenn gewünscht
          k := VorneZeilenIgnorieren;
          while (slEinzelCsv.Count > 0) and (k > 0) do
          begin
            slEinzelCsv.Delete(0);
            Dec(k);
          end;

          //Entfernt vorne Zeilen, wenn gewünscht
          k := HintenZeilenIgnorieren;
          while (slEinzelCsv.Count > 0) and (k > 0) do
          begin
            slEinzelCsv.Delete(slEinzelCsv.Count - 1);
            Dec(k);
          end;

          slGrosseCsv.AddStrings(slEinzelCsv);
        finally
          slEinzelCsv.Free;
        end;
      end;

      slGrosseCsv.SaveToFile(OutPath);
      MessageDlg('CSV-Dateien zusammengefügt und erfolgreich gespeichert ' +
        'unter: "' + OutPath + '".', mtInformation, [mbOk], 0);
    finally
      slGrosseCsv.Free;
    end;
  finally
    slDateiListe.Free;
  end;
end;
end;

Geändert von Dade (18. Apr 2015 um 23:45 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:53 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz