Thanks. I was hesitant to do so because I am still too new to include an attachment. Also, i was worried that there might be too much code. Since I don't want to leave out something that is potentially important, I am including all of the code (a little self-consciously, I might add

). But since I have been muddling along in Delphi, other pointers (no pun intended) to improve my code are most welcome too!
Basically, I want to compute two parameters for a non-linear regression by means of iterating over a range of values for each of the two parameters. I will then pick those values that correspond to the lowest residual sum of squares as the best (least squares) estimates.
Here is my code (in its entirety). I have highlighted the lines where I get the error. Sorry about the lengthy code and thanks in advance for any help! Also, please note that I get the same error message when I have included "ShareMem" in my uses clause. I have also downloaded sometjhing called "FastShareMem" that was supposed to mitigate some issues that ShareMem could not. But I get the same error message.
----------------------------
unit HillSlope;
interface
uses
Sharemem, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Spin, Math;
type
THillSlopeRegr = class(TForm)
HelpCmdBtn: TButton;
OpenFileCmdBtn: TButton;
CloseFormCmdBtn: TButton;
ComputeCmdBtn: TButton;
OpenFileEditBx: TEdit;
OpenDialog1: TOpenDialog;
Label1: TLabel;
YesHeadersRadBtn: TRadioButton;
NoHeadersRadBtn: TRadioButton;
GroupBox1: TGroupBox;
Label2: TLabel;
Label3: TLabel;
EC50_LowSpinEdit: TSpinEdit;
EC50_HighSpinEdit: TSpinEdit;
Hill_LowSpinEdit: TSpinEdit;
Hill_HighSpinEdit: TSpinEdit;
Label4: TLabel;
Label5: TLabel;
procedure HelpCmdBtnClick(Sender: TObject);
procedure CloseFormCmdBtnClick(Sender: TObject);
procedure OpenFileCmdBtnClick(Sender: TObject);
procedure ComputeCmdBtnClick(Sender: TObject);
function Estimate(N_EC, N_Hill: integer; X_Array, Y_Array: array of double; EC50_Low, EC50_High, Hill_Low, Hill_High: double; EC50_Incr, Hill_Incr: double): string;
private
{ Private declarations }
public
{ Public declarations }
end;
var
HillSlopeRegr: THillSlopeRegr;
implementation
{$R *.dfm}
procedure THillSlopeRegr.HelpCmdBtnClick(Sender: TObject);
var
S: string;
begin
S := 'This program computes the Hillslope regression for the pair of' + #13#10 +
'input variables, X and Y, where X is the percent animals that ' + #13#10 +
'have shown the required response, and Y is the dose used.' + #13#10 +
'' + #13#10 +
'INSTRUCTIONS:'+ #13#10 +
'1. Upload the input data as a comma-delimited (.csv) file, with' + #13#10 +
' two columns, X and Y, and press the "Compute" button. ' + #13#10 +
'2. Wait for the message "Done!"' + #13#10 +
'3. The results will be in a .csv file, and will be saved in the' + #13#10 +
' same folder as the input file.' + #13#10 +
'4. The output file will contain the input variables, X and Y,' + #13#10 +
' the expected Y values (Y-hat), the lower and upper limits' + #13#10 +
' for the confidence interval (CI) and the prediction interval (PI)';
ShowMessage(S);
end;
procedure THillSlopeRegr.OpenFileCmdBtnClick(Sender: TObject);
begin
if OpenDialog1.Execute then OpenFileEditBx.Text := OpenDialog1.FileName
else ShowMessage('Cannot open file!');
end;
procedure THillSlopeRegr.ComputeCmdBtnClick(Sender: TObject);
var
I,J,K, Posit, N_EC, N_Hill : integer;
Chr: char;
RowData, X_Str, Y_Str, EstimatedValues: string;
X_Value, Y_Value, EC50_Low, EC50_High, Hill_Low, Hill_High, EC50, EC50_Range, EC50_Incr, HillSlope, Hill_Range, Hill_Incr: double;
InputFile, X_List, Y_List, YHat_List, LLCI_List, ULCI_List, LLPI_List, ULPI_List, Output: TStringList;
X_Array, Y_Array, YHat_Array, EC50_Array, Hill_Array, LLCI_Array, ULCI_Array, LLPI_Array, ULPI_Array: array of double;
const Letters = ['A'..'Z', 'a'..'z'];
begin
try
InputFile := TStringList.Create;
X_List := TStringList.Create;
Y_List := TStringList.Create;
YHat_List := TStringList.Create;
LLCI_List := TStringList.Create;
ULCI_List := TStringList.Create;
LLPI_List := TStringList.Create;
ULPI_List := TStringList.Create;
Output := TStringList.Create;
InputFile.LoadFromFile(OpenFileEditBx.Text);
if YesHeadersRadBtn.Checked = True then K := 1
else if NoHeadersRadBtn.Checked = True then K := 0
else ShowMessage('Does your file have headers?' + #13#10 + 'Please answer Yes or No.');
SetLength(X_Array, InputFile.Count - K);
SetLength(Y_Array, InputFile.Count - K);
N_EC := 10;
N_Hill := 10;
EC50_Range := EC50_HighSpinEdit.Value - EC50_LowSpinEdit.Value;
EC50_Incr := EC50_Range/N_EC;
Hill_Range := Hill_HighSpinEdit.Value - Hill_LowSpinEdit.Value;
Hill_Incr := Hill_Range/N_Hill;
for I := K to InputFile.Count-1 do//value of K depends on presence/abssence of headers in input file
begin
RowData := Trim(InputFile[I]);
Posit := Pos(',', RowData) - 1;//excluding the comma
X_Str := '';
for J := 1 to Posit do X_Str := X_Str + RowData[J];
X_Str := Trim(X_Str);
//check if there are any non-numerical data (letters) in the values
for J := 1 to Length(X_Str) do
begin
Chr := X_Str[J];
if Chr in Letters then
begin
MessageDlg('Error! Your file has non-numerical data in row #' + IntToStr(I) + '!', mtError, [mbAbort], 0);
Exit;
end
else continue;
end;
X_Value := StrToFloat(X_Str);
X_Array[I-1] := X_Value;
Y_Str := '';
for J := (Posit+2) to Length(RowData) do Y_Str := Y_Str + RowData[J];
Y_Str := Trim(Y_Str);
//check if there are any non-numerical data (letters) in the values
for J := 1 to Length(Y_Str) do
begin
Chr := Y_Str[J];
if Chr in Letters then
begin
MessageDlg('Error! Your file has non-numerical data in row #' + IntToStr(I) + '!', mtError, [mbAbort], 0);
Exit;
end
else continue;
end;
Y_Value := StrToFloat(Y_Str);
Y_Array[I-1] := Y_Value;
// ShowMessage(FloatToStr(X_Value) + ',' + FloatToStr(Y_Value));
end;
{The formula for the Hillslope regression is y-hat = min + (Max - Min)/(1 + (X/EC50)^Hillslope),
where Min and Max are constrained to 0% and 100%, respectively. This program needs to
iterate for y-hat values through the EC50_Range and Hill_Range, using the EC50_Incr and
Hill_Incr as the respective increments, and then those values of EC50 and Hillslope
are picked as the best estimates that result in the lowest Residual SS, that is:
Sum(Y - y-hat)2.
}
//Obtain the estimated values of EC50 and Hillslope as a single comma-delimited string
EC50_Low := EC50_LowSpinEdit.Value;
EC50_High := EC50_HighSpinEdit.Value;
Hill_Low := Hill_LowSpinEdit.Value;
Hill_High := Hill_HighSpinEdit.Value;
EC50_Incr := (EC50_HighSpinEdit.Value - EC50_LowSpinEdit.Value)/N_EC;
Hill_Incr := (Hill_HighSpinEdit.Value - Hill_LowSpinEdit.Value)/N_Hill;
EstimatedValues := Estimate(N_EC, N_Hill, X_Array, Y_Array, EC50_Low, EC50_High, Hill_Low, Hill_High, EC50_Incr, Hill_Incr); ShowMessage(EstimatedValues);
finally
InputFile.Free;
X_List.Free;
Y_List.Free;
YHat_List.Free;
LLCI_List.Free;
ULCI_List.Free;
LLPI_List.Free;
ULPI_List.Free;
Output.Free;
ShowMessage('Done!');
end;
end;
function THillSlopeRegr.Estimate(N_EC, N_Hill: integer; X_Array, Y_Array: array of double; EC50_Low, EC50_High, Hill_Low, Hill_High: double; EC50_Incr, Hill_Incr: double): string;
var
I, J, K, NumValues: integer;
Min, Max, X_Val, Y_Val, A, B, y_hat, Res_Sq, ResSS, Min_ResSS, EC50, Low_EC50, Low_Hill, Hill: double;
RSS_Array, MinSS_Array: array of double;
EC50_Array, Hill_Array, ResSS_Array: array of array of double;//multiple YHat values for each X value, one for each iteration
YHat_Array: array of array of array of double;
begin
try
Min := 0;
Max := 100;
NumValues := Length(X_Array);
SetLength(ResSS_Array, N_EC+1, 11);//1001*1001 matrix of residual sum of squares - for each X,Y value
SetLength(YHat_Array, NumValues, N_EC+1, N_Hill+1);
SetLength(EC50_Array, N_EC+1, N_Hill+1);
SetLength(Hill_Array, N_EC+1, N_Hill+1);
for I := 0 to N_EC do
begin
for J := 0 to N_Hill do
begin
ResSS_Array[I,J] := 0;
EC50_Array[I,J] := 0;
Hill_Array[I,J] := 0;
end;
end;
for I := 0 to NumValues - 1 do
begin
for J := 0 to N_EC do //1001 iterations to accommodate variations in the EC50 value
begin
for K := 0 to N_Hill do //1001 iterations to accommodate variations in the HillSlope value
begin
YHat_Array[I,J,K] := 0;
end;
end;
end;
//iterate over 1000 Hillslope values nested within 1000 EC50 values
for I := 0 to NumValues - 1 do
begin
X_Val := X_Array[I];
Low_EC50 := EC50_Low;
for J := 0 to N_EC do //1001 iterations to accommodate variations in the EC50 value
begin
Low_Hill := Hill_Low;
for K := 0 to N_Hill do //1001 iterations to accommodate variations in the HillSlope value
begin
y_hat := Min + (Max - Min)/(1 + Power((X_Val/Low_EC50), Low_Hill));
YHat_Array[I,J,K] := y_Hat;
EC50_Array[J,K] := Low_EC50;
Hill_Array[J,K] := Low_Hill;
Low_Hill := Low_Hill + Hill_Incr;
end;
Low_EC50 := Low_EC50 + EC50_Incr;
end;
end;
//now compute ResSS for every combination of EC50 and Hill value
for I := 0 to N_EC do
begin
for J := 0 to N_Hill do
begin
ResSS := 0;
for K := 0 to Length(X_Array) - 1 do
begin
Y_Val := Y_Array[K];
y_hat := YHat_Array[K,I,J];
Res_Sq := Power((Y_Val - y_hat), 2);
ResSS := ResSS + Res_Sq;
end;
ResSS_Array[I,J] := ResSS;
end;
end;
SetLength(RSS_Array, N_EC);
SetLength(MinSS_Array, N_EC);
for I := 0 to N_EC do
begin
RSS_Array[I] := 0;
MinSS_Array[I] := 0;
end;
//find the minimum Res SS in a nested manner
for I := 0 to N_EC do
begin
for J := 0 to N_Hill do
begin
RSS_Array[J] := ResSS_Array[I,J];
end;
MinSS_Array[I] := MinValue(RSS_Array);//array of mimimum SS among Hill values within EC50 value
end;
Min_ResSS := MinValue(MinSS_Array);//minimum SS value
for I := 0 to N_EC do
begin
for J := 0 to N_Hill do
begin
ResSS := ResSS_Array[I,J];
if (ResSS = Min_ResSS) then
begin
EC50 := EC50_Array[I,J];
Hill := Hill_Array[I,J];
end
else continue;
end;
end;
finally
Result := FloatToStr(EC50) + ', ' + FloatToStr(Hill);
end;
end;
procedure THillSlopeRegr.CloseFormCmdBtnClick(Sender: TObject);
begin
HillSlopeRegr.Close;
end;
end.