Quote:[1]Posted by et33 on 20 Nov 2005 11:18 AM[/1]
Hi,
Help - I'm stuck!! I'm trying to copy a list of countries from a csv file to text file and I'm trying to get to the position of each country on each line?
Thanks ,
Junior
Hi,
Your question sounds very confusing. I assume that you have two questions here.
1. How to copy a list of countries from a csv file to text file?
All you need to do is to write a copy file function to copy a csv file to a text file:
procedure FileCopy(const FileFrom, FileTo: string) ;
var FromF, ToF: file;
NumRead, NumWritten: Word;
Buffer: array[1..2048] of Byte;
begin
AssignFile(FromF, FileFrom) ;
Reset(FromF, 1) ;
AssignFile(ToF, FileTo) ;
Rewrite(ToF, 1) ;
repeat
BlockRead(FromF, Buffer, SizeOf(Buffer), NumRead) ;
BlockWrite(ToF, Buffer, NumRead, NumWritten) ;
until (NumRead = 0) or (NumWritten <> NumRead) ;
CloseFile(FromF) ;
CloseFile(ToF) ;
end;
2. How to get the position of each country on each line?
Assumption Each country is being found on different lines as shown below:
Africa
Australia
Austria
China
Japan
Malaysia
Phillippines
and the file content is loaded into a TStringList to be read to show the user each line of the country with a sequence number by it's side.
procedure GetCountry(CountryFilePath: string);
var CountryLst : TStringList;
i : integer;
begin
//Check to ensure that the file exists
if not FileExists(CountryFilePath) then begin
beep;
ShowMessage('Country file: ' + CountryFilePath + ' does not exist.');
exit;
end;
//Loads contents into CountryLst
try
CountryLst := TStringList.Create;
CountryLst.Clear;
CountryLst.LoadFromFile(CountryFilePath);
for i := 0 to CountryLst.Count - 1 do
ShowMessage(IntToStr(i + 1) + ': ' + CountryLst.Strings); //Shows: 1: Africa and lets the user to click on the OK button before continuing
finally
CountryLst.Free;
end;
end;
Hope this helps.
Enter your message below
Sign in or Join us (it's free).