Reputation: 51
I try to doing some unit for accessing text files (CSV). I do this:
type
TCSV_Data = class
private
stFile:TextFile;
public
constructor Create(path:string);
end;
.
.
.
constructor TCSV_Data.Create(path: string);
begin
assignfile(stFile,ces);
end;
Problem is, when I call constructor, method assignfile will rise an exception: "Access violation at address 004036FF in module 'myprog.exe'. Write of address 00000010."
When I use a local procedure variable, everything is ok, but I need stFile-handle for accessing this file in other methods.
What can I do with this?
Upvotes: 0
Views: 585
Reputation: 612794
You are probably calling the constructor incorrectly. Almost certainly you are writing:
var
CsvData: TCSV_Data;
....
CsvData.Create(path);
Such code is not correct. Here is how you do it correctly:
var
CsvData: TCSV_Data;
....
CsvData := TCSV_Data.Create(path);
try
// do stuff with CsvData
finally
CsvData.Free;
end;
Upvotes: 3