I want to create and manage a heartbeat file in a thread - I was doing this on the main UI thread but it was causing the app to be non-responsive so I'm moving it out into a thread of its own.
I am using a TIniPropStorage as the container of the heartbeat file as it gives me easy access to a couple of values stored in the file.
I am declaring the object as:
heartbeatFile: TIniPropStorage;
but when I try to assign the IniFileName I get an External: SIGNSEGV crash at run time. The assembler view shows that it is the fpc_ansistr_assign that is the problem.
Do I need to create the instance of the object before I can use it (because it is not auto created as its not on the main thread?) ?
Or is something else wrong here?
This is the relevant code:
uses
Classes, SysUtils, FileUtil, IniPropStorage;
type
{THeartBeatThread}
THeartBeatThread = class(TThread)
heartbeatFile: TIniPropStorage;
private
fStatusText: string;
procedure ShowStatus;
procedure heartbeat();
protected
procedure Execute; override;
public
var
heartbeatFileName: AnsiString;
heartbeatPeriod: Integer;
beating: Boolean;
constructor Create(CreateSuspended: boolean);
end;
implementation
{ THeartBeatThread }
uses MainUnit;
procedure THeartBeatThread.ShowStatus;
begin
MainForm.addToLog(fStatusText);
end;
procedure THeartBeatThread.Execute;
begin
heartbeatFile.IniFileName:=heartbeatFileName;
end;
{etc etc}
I've tried adding heartbeatFile := TIniPropStorage.Create(); before trying to assign the filename, but I do not know what TComponent I should be using as the argument to the Create() method.
Thanks,
FM