String access error in class



I have included a stripped down version of a class I am using to store configuration data in an ini file.

This works when I am using it from a simple console app. But when I include it in a larger project, the constructor throws this error:

'Access violation at address 004050FC in module 'app.exe'. Write of address 00000008'.

This happens on the line: ComputerName:='test';

Obviously 00000008 is not a valid address. But I thought delphi handles string address automatically.

What have I done wrong?

Thanks.



unit Configuration;

interface

uses windows,inifiles,sysutils;

type
TConfig = Class(TObject)
public
FileName:string;

ComputerName:String;
//...

constructor Create(); overload;
constructor Create(FN:String); overload;

//procedure saveFile(); overload;
//procedure saveFile(FN:string); overload;

//function checkErrors():string;
//procedure fixErrors();


end;


var

IniFile : TIniFile;

implementation

constructor TConfig.Create(Fn:string)overload;
begin

IniFile := TIniFile.Create(Fn);
ComputerName:='test';

filename:=fn;
//savefile(fn);

end;

constructor TConfig.Create()overload;
begin
Create(Paramstr(0)+'.ini');
end;

end.
.



Relevant Pages

  • Re: String access error in class
    ... configuration data in an ini file. ... But when I include it in a larger project, the constructor throws this error: ... constructor Create; overload; ... IniFile: TIniFile; ...
    (alt.comp.lang.borland-delphi)
  • Re: Proposal: Default Parameters/Named Parameters
    ... its referenced assemblies changes means the burned-in defaults would be ... Anders' mentioned the possibility of object initialization syntax that may ... If you didn't want to expose your constructor parameters as properties ... I like this a lot (especially since it's avoids the overload resolution ...
    (microsoft.public.dotnet.framework.clr)
  • Re: how do you overload methods...
    ... I believe that the constructor of the TreeViewCollection has been set to ... The error message is a bit misleading though (it suggests that there is a ... public constructor that does not have zero args - and hence in that case you ... > different return type does not constitute an overload. ...
    (microsoft.public.dotnet.languages.csharp)
  • Accessing controls on another form.
    ... >>> End Sub ... > Now the problem is I have used the overload in normal funtions and subs ... Dave, overloading a constructor is done the exact same way, although I'm ... Store the Form1 reference for later use. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Accessing controls on another form.
    ... >> Now the problem is I have used the overload in normal funtions and subs ... > Dave, overloading a constructor is done the exact same way, although I'm ... Store the Form1 reference for later use. ... > private Form1 myParent; ...
    (microsoft.public.dotnet.languages.vb)