How to import a csv file into a delphi app? Hi! I need to import to my application in delphi 2006 using firebird 2.0 an address book I have exported with csv extension. How do I do that? Thank You! Eduardo Tavares [link=http://www.eduardotavares.com.br]www.EduardoTavares.com.br[/link] Plz accept if it helps.I always do. "Daddy,what does Formatting C:... mean?" --------------------------------------------- Borland Delphi 2006 |
#2 | |||
| |||
![]() Ive used a stringlist which has a commatext method which will create a stringlist of the current values (Array) in the code below the Ttask create method loads a CSV string from the input file and creates objects as it loops through the file. constructor tTask.Create(sTask_string: string); var MSL: tstringlist; //Temporary Stringlist for Task Class dToday : tDate; begin if sTask_string = '--' then begin //Is reaching here in the Correct Situation dToday := Dateof(Date); sDescription := 'New Task'; dDate_Set := dToday; dDate_Due := dToday + 1; bIsComplete := false; sNotes := 'Notes'; end else begin MSL := tStringList.Create; MSL.CommaText:= sTask_string; sDescription := MSL[0]; dDate_Set := strtoDate(MSL[1]); dDate_Due := strtoDate(MSL[2]); bIsComplete := strtobool(MSL[3]); sNotes := MSL[4]; MSL.Free; end; end; procedure TForm1.LoadFromFile(); var f: textfile; //Input File Openstr: string; //Temporary String to Hold Line Input from File ThisTask : tTask; //Class to Hold Object before it is assigned to Listbox. begin OpenDialog1.DefaultExt := 'TSK'; OpenDialog1.Filter := 'Task File|*.TSK'; OpenDialog1.Execute; if OpenDialog1.FileName = '' then begin showmessage('No File Selected'); end else begin ClearScreen(); ExtractFilePath(application.ExeName); AssignFile(f,OpenDialog1.FileName); Reset(f); try while not eof(f) do begin Readln(f,OpenStr); ThisTask := tTask.Create(OpenStr); //In CVS used a Stringlist to Create file; ListBox1.Items.AddObject(ThisTask.sDescription,tOb ject(ThisTask)); end; finally CloseFile(f); end; end; ChangesMade := false; Statusbar1.Panels[0].Text := OpenDialog1.FileName; UpDateFileHistory(OpenDialog1.FileName); MyFileName := OpenDialog1.FileName; end; |
#3 | |||
| |||
![]() You may use SMImport suite: http://www.scalabium.com/smi With best regards, Mike Shkolnik http://www.scalabium.com |
联系客服