Forum > Beginners
load csv
(1/1)
scons:
Hi
I want to load a csv file, and then delete some columns out of it.
I have this code so far:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- GetDir_1: TDirectoryEdit; .... procedure GetDir_1Change(Sender: TObject); procedure LoadGridFromCSVFile(Grid: TStringGrid;AFilename: string; ADelimiter:Char=';'; WithHeader:boolean=true; AddRows:boolean=true); .... procedure TForm1.btnGetClick(Sender: TObject);var AProcess: TProcess;begin AProcess := TProcess.Create(nil); AProcess.Executable := 'c:\folder\dbf2csv.exe'; AProcess.Parameters.Add(GetDir_1.Directory + '\folder\file.dbf'); AProcess.Execute; AProcess.Free;end; procedure TForm1.LoadGridFromCSVFile(Grid: TStringGrid; (GetDir_1.Directory + '\folder\file.csv'); ADelimiter: Char=';'; WithHeader: boolean=true;);var TheStream: TFileStreamUtf8;begin TheStream:=TFileStreamUtf8.Create(AFileName,fmOpenRead or fmShareDenyWrite); try LoadFromCSVStream(TheStream, ADelimiter, WithHeader); finally TheStream.Free; end;end;
the file.csv is always in the same folder structure, of course the directory and root_folder of the dbf not, so I want fill in the filename as a variable so it changes automatically everytime I select another directory\root_folder.
I get an error on this part in TForm1.LoadGridFromCSVFile:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- (GetDir_1.Directory + '\folder\file.csv')
unit1.pas(71,57) Fatal: Syntax error, "identifier" expected but "(" found
How can I get this solved in a decent way ?
Thanks
wp:
Use AFilename in the declaration of the procedure TForm1.LoadGridFromCSVFile. Combine this when you *call* (not: *declare*) the procedure.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.LoadGridFromCSVFile(Grid: TStringGrid; AFileName: String; ADelimiter: Char=';'; WithHeader: boolean=true;);begin ....end; procedure TForm1.ButtonLoadClick(Sender: TObject);begin LoadGridFromCSVFile(Grid, GetDir_1.Directory + '\folder\file.csv', #9, false);end;
scons:
THanks wp, I will try your solution.
Navigation
[0] Message Index