Re: String access error in class



E Sterrett wrote:

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.
Try calling the inherited create first maybe?


http://webpages.charter.net/jamie_5";

.



Relevant Pages

  • 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. ... 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: String access error in class
    ... configuration data in an ini file. ... include it in a larger project, the constructor throws this error: ... IniFile: TIniFile; ... Constructors can be called in either of two ways: on a class reference ...
    (alt.comp.lang.borland-delphi)
  • Class events
    ... which contains configuration data for my ... Unfortunately I cannot use a static implementation of the class, ... requires a constructor. ... Dave ...
    (microsoft.public.dotnet.languages.csharp)
  • 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)