Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0

    EAccessViolation for no apparent reason!


    I have a procudure that runs fine and outputs accurate information. It even executes the final command where I ask it to display "Done!" and displays the message box with "Done!" on it. After that, the darn thing gives me an Access violation error message. Been wrestling with it all day, but I can't figure out what is going on. Would appreciate any insights.

    Thanks, and here is the procedure:

    procedure THillSlopeRegr.ComputeCmdBtnClick(Sender: TObject);
    var
    I, K, NumValues: integer;
    EstimatedValues: string;
    EC50, HillSlope, SumSqDevX, SumSqDevY, SumCrossProds, SumSqDev_YX, MnSumSqDev_YX: double;
    InputFile: TStringList;
    X_Array, Y_Array, YHat_Array, SqDevX_Array, SqDevY_Array, CrossProds_Array, SD_YX_Array, CILL_Array, CIUL_Array, SENewY_Array, PILL_Array, PIUL_Array: TVal_Array;
    MyFile: TextFile;
    const Letters = ['A'..'Z', 'a'..'z'];
    begin
    InputFile := TStringList.Create;
    try
    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);

    //Get X and Y values
    X_Array := GetXValues(K, InputFile);
    Y_Array := GetYValues(K, InputFile);
    NumValues := Length(X_Array);

    //Obtain the estimated values of EC50 and Hillslope as a single comma-delimited string
    try
    EstimatedValues := Estimate(NumValues, X_Array, Y_Array);
    except
    if (EstimatedValues = '') then MessageDlg('unable to compute EC50 and HillSlope parameters!', mtError, [mbOK], 0);
    end;
    ShowMessage(EstimatedValues);

    //get the two parameters from the comma delimited string result of the Estimate function
    EC50 := GetFirstValue(EstimatedValues);
    HillSlope := GetSecondValue(EstimatedValues);

    //Obtain y-hat values
    YHat_Array := Regress(NumValues, K, X_Array, EC50, HillSlope);

    //The following computations are for the CI and PI - based on Snedecor and Cochran (S&C) pp 160-167

    //compute array of SumSq dev from mean for X and Y
    SqDevX_Array := GetSqDevVals(NumValues, X_Array);
    SumSqDevX := Sum(SqDevX_Array);
    SqDevY_Array := GetSqDevVals(NumValues, Y_Array);
    SumSqDevY := Sum(SqDevY_Array);

    //Compute array of sum of products of
    CrossProds_Array := GetCrossProds(NumValues, X_Array, Y_Array);
    SumCrossProds := Sum(CrossProds_Array);

    //Compute SumSqDev_YX or Sum(d2_YX) in S&C
    SumSqDev_YX := SumSqDevY - Power(SumCrossProds, 2)/SumSqDevX;

    //Compute Mean SumSqDev_YX (s2_YX in S&C)
    MnSumSqDev_YX := SumSqDev_YX/(NumValues - 2);

    //Compute ResMnSq of predicted population regr line
    SD_YX_Array := GetSD_YX(NumValues, MnSumSqDev_YX, SumSqDevX, SqDevX_Array);

    //Get Confidence Limits
    CILL_Array := GetConfLL(NumValues, YHat_Array, SD_YX_Array);
    CIUL_Array := GetConfUL(NumValues, YHat_Array, SD_YX_Array);

    //Compute SE of new Y value
    SENewY_Array := GetSENewY(NumValues, MnSumSqDev_YX, SumSqDevX, SqDevX_Array);

    //Get Prediction Limits
    PILL_Array := GetPredLL(NumValues, YHat_Array, SENewY_Array);
    PIUL_Array := GetPredUL(NumValues, YHat_Array, SENewY_Array);

    AssignFile(MyFile, 'C:\Users\...\Results.csv');
    ReWrite(MyFile);
    WriteLn(MyFile, 'X ' + ', ' + 'Y ' + ', ' + 'Y_Hat ' + ', ' + 'CILL ' + ', ' + 'CIUL ' + ', ' + 'PILL ' + ', ' + 'PIUL');
    for I := 0 to NumValues - 1 do
    begin
    WriteLn(MyFile, FloatToStr(X_Array[I]) + ', ' + FloatToStr(Y_Array[I]) + ', ' +
    FloatToStr(YHat_Array[I]) + ', ' + FloatToStr(CILL_Array[I]) + ', ' +
    FloatToStr(CIUL_Array[I]) + ', ' + FloatToStr(PILL_Array[I]) + ', ' +
    FloatToStr(PIUL_Array[I]));
    end;
    finally
    CloseFile(MyFile);
    InputFile.Free;
    X_Array := nil;
    Y_Array := nil;
    YHat_Array := nil;
    SqDevX_Array := nil;
    SqDevY_Array := nil;
    CrossProds_Array := nil;
    SD_YX_Array := nil;
    CILL_Array := nil;
    CIUL_Array := nil;
    SENewY_Array := nil;
    PILL_Array := nil;
    PIUL_Array := nil;
    ShowMessage('Done!');
    end;
    end;
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    I would make sure that each of your array bounds are defined correctly, that the individual array elements are addressable between 0 and NumValues-1, since you are iterating through them at the end of the procedure.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0
    Originally Posted by majlumbo
    I would make sure that each of your array bounds are defined correctly, that the individual array elements are addressable between 0 and NumValues-1, since you are iterating through them at the end of the procedure.
    Thanks mailjumbo. Not sure what you mean by "iterating through them at the end of the procedure" though. Do you mean where I write each value to MyFile? But MyFile is written perfectly (all the values are there.) Also, I have tried commenting out the parts where I output the results (from the "AssignFile" statement to the "end" before "finally" and also all the statements that release the memory (Input.Free and all the Array := nil statements). It still gives the Access Violation error. What is trying to access AFTER the "ShowMessage(Done!) statement? There is nothing there.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    Unfortunately, without your input file, and all your GetXXX method functions, there isn't much I can do to help figure it out.

    As far as "iterating through..." I meant this section

    Code:
    for I := 0 to NumValues - 1 do
    begin
       WriteLn(MyFile, FloatToStr(X_Array[I]) + ', ' + FloatToStr(Y_Array[I]) + ', ' +
       FloatToStr(YHat_Array[I]) + ', ' + FloatToStr(CILL_Array[I]) + ', ' +
       FloatToStr(CIUL_Array[I]) + ', ' + FloatToStr(PILL_Array[I]) + ', ' +
       FloatToStr(PIUL_Array[I]));
    end;
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0
    Thanks mailjumbo. What I find strange about this error is that it seems to show up AFTER everything is done. This is what makes me think that there is nothing wrong with any of my numerous functions. That is why I did not reproduce my entire code here. The results file, "MyFile" is downloaded correctly and the results are correct - I have checked them manually. The program even executes the last command correctly, where it displays the message "Done!". It is AFTER that that it gives an access violation error. I have now spend close to a week on this problem and am still unable to figure out why. There is nothing else to access after this last command. So why does it give that error? Not sure if you meant the input file that I am inputting to the program, but if that's what you meant, here it is:

    X,Y
    3,1.136
    3,1.923
    3,2.941
    6,2.273
    6,1.923
    6,2.941
    9,2.273
    9,3.846
    9,2.941
    12,5.769
    13,2.273
    13,3.922
    16,2.273
    16,5.769
    16,3.922
    19,3.409
    19,5.769
    19,4.902
    22,3.409
    22,7.692
    22,4.902
    25,3.409
    25,7.692
    25,6.863
    28,7.692
    29,3.409
    29,6.863
    31,0.000
    31,7.692
    32,3.409
    32,6.863
    35,0.943
    35,3.409
    35,7.692
    35,8.824
    38,0.943
    38,5.682
    38,9.615
    38,8.824
    41,1.887
    41,6.818
    41,9.615
    41,9.804
    44,3.774
    44,7.955
    44,9.615
    44,12.745
    47,3.774
    47,9.615
    48,7.955
    48,13.725
    51,3.774
    51,7.955
    51,11.538
    51,14.706
    54,3.774
    54,10.227
    54,11.538
    54,16.667
    57,3.774
    57,10.227
    57,13.462
    57,19.608
    60,3.774
    60,10.227
    60,13.462
    60,19.608
    63,4.717
    63,13.462
    64,10.227
    64,21.569
    67,4.717
    67,10.227
    67,13.462
    67,21.569
    70,6.604
    70,10.227
    70,13.462
    70,21.569
    73,6.604
    73,11.364
    73,17.308
    73,21.569
    76,8.491
    76,11.364
    76,17.308
    76,21.569
    79,9.434
    79,17.308
    80,15.909
    80,21.569
    82,9.434
    82,17.308
    83,15.909
    83,22.549
    86,9.434
    86,15.909
    86,17.308
    86,22.549
    89,10.377
    89,18.182
    89,17.308
    89,22.549
    92,11.321
    92,18.182
    92,19.231
    92,22.549
    95,12.264
    95,20.455
    95,19.231
    96,22.549
    98,13.208
    98,19.231
    99,20.455
    99,22.549
    102,13.208
    102,20.455
    102,21.154
    102,23.529
    105,16.038
    105,21.591
    105,21.154
    105,24.510
    108,17.925
    108,21.591
    108,21.154
    109,24.510
    111,18.868
    111,21.591
    111,21.154
    112,24.510
    114,21.698
    114,21.154
    115,22.727
    115,24.510
    118,25.472
    118,23.864
    118,23.077
    118,24.510
    121,26.415
    121,23.864
    121,23.077
    122,24.510
    124,26.415
    124,25.000
    124,25.000
    125,25.490
    127,27.358
    127,25.000
    127,28.846
    128,25.490
    130,27.358
    130,30.769
    131,27.273
    131,25.490
    133,30.769
    134,29.245
    134,30.682
    134,26.471
    137,29.245
    137,30.682
    137,32.692
    137,26.471
    140,30.189
    140,31.818
    140,32.692
    141,26.471
    143,31.132
    143,35.227
    143,32.692
    144,26.471
    146,33.019
    146,35.227
    146,32.692
    147,26.471
    149,33.962
    149,32.692
    150,37.500
    150,26.471
    153,34.906
    153,38.636
    153,32.692
    154,28.431
    156,35.849
    156,42.045
    156,32.692
    157,28.431
    159,36.792
    159,43.182
    159,34.615
    160,29.412
    162,38.679
    162,45.455
    162,34.615
    163,31.373
    165,39.623
    165,34.615
    166,46.591
    166,31.373
    169,41.509
    169,46.591
    169,40.385
    169,32.353
    172,45.283
    172,46.591
    172,40.385
    173,32.353
    175,46.226
    175,47.727
    175,40.385
    176,32.353
    178,47.170
    178,48.864
    178,42.308
    179,33.333
    181,42.308
    182,48.113
    182,48.864
    182,33.333
    185,50.000
    185,50.000
    185,44.231
    185,34.314
    188,51.887
    188,52.273
    188,44.231
    189,36.275
    191,51.887
    191,53.409
    191,48.077
    192,38.235
    194,54.545
    194,50.000
    195,52.830
    195,38.235
    197,50.000
    198,52.830
    198,55.682
    198,39.216
    201,52.830
    201,57.955
    201,50.000
    201,40.196
    204,53.774
    204,57.955
    204,50.000
    205,40.196
    207,54.717
    207,59.091
    207,50.000
    208,41.176
    210,54.717
    210,59.091
    210,50.000
    211,41.176
    213,53.846
    214,55.660
    214,59.091
    214,42.157
    217,56.604
    217,61.364
    217,53.846
    217,42.157
    220,58.491
    220,62.500
    220,55.769
    221,43.137
    223,59.434
    223,62.500
    223,55.769
    224,45.098
    226,59.434
    226,55.769
    227,64.773
    227,45.098
    229,55.769
    230,60.377
    230,65.909
    230,45.098
    232,55.769
    233,60.377
    233,65.909
    233,45.098
    236,62.264
    236,65.909
    236,59.615
    237,46.078
    239,59.615
    240,62.264
    240,65.909
    240,46.078
    242,59.615
    243,63.208
    243,69.318
    243,48.039
    245,59.615
    246,64.151
    246,70.455
    246,48.039
    248,61.538
    249,65.094
    249,71.591
    250,48.039
    252,66.038
    252,71.591
    252,61.538
    253,48.039
    255,71.591
    255,61.538
    256,66.038
    256,48.039
    258,61.538
    259,70.755
    259,71.591
    259,49.020
    261,61.538
    262,70.755
    262,71.591
    262,49.020
    264,61.538
    265,71.698
    265,71.591
    265,52.941
    268,71.698
    268,71.591
    268,69.231
    269,52.941
    271,71.591
    271,69.231
    272,72.642
    272,53.922
    274,69.231
    275,72.642
    275,72.727
    275,54.902
    277,71.154
    278,73.585
    278,73.864
    278,54.902
    280,71.154
    281,74.528
    281,73.864
    281,54.902
    284,74.528
    284,73.864
    284,71.154
    285,54.902
    287,74.528
    287,73.864
    287,71.154
    288,54.902
    290,71.154
    291,75.472
    291,73.864
    291,55.882
    293,71.154
    294,77.358
    294,73.864
    294,56.863
    296,73.077
    297,77.358
    297,73.864
    297,56.863
    300,77.358
    300,73.864
    300,73.077
    301,57.843
    303,77.358
    303,73.077
    304,73.864
    304,57.843
    306,75.000
    307,78.302
    307,73.864
    307,57.843
    309,75.000
    310,79.245
    310,73.864
    310,57.843
    312,78.846
    313,80.189
    313,75.000
    313,58.824
    316,75.000
    316,80.769
    316,58.824
    317,82.075
    319,82.692
    320,82.075
    320,76.136
    320,58.824
    322,82.692
    323,82.075
    323,77.273
    323,58.824
    325,82.692
    326,82.075
    326,77.273
    326,59.804
    328,82.692
    329,83.019
    329,79.545
    329,59.804
    332,79.545
    332,82.692
    332,61.765
    333,83.962
    335,82.692
    336,83.962
    336,79.545
    336,62.745
    338,82.692
    339,84.906
    339,79.545
    339,62.745
    341,82.692
    342,84.906
    342,80.682
    342,62.745
    344,82.692
    345,84.906
    345,80.682
    345,62.745
    348,84.906
    348,82.692
    348,62.745
    349,80.682
    351,82.692
    352,84.906
    352,80.682
    352,64.706
    354,82.692
    355,84.906
    355,80.682
    355,65.686
    357,82.692
    358,84.906
    358,65.686
    359,80.682
    360,82.692
    361,85.849
    361,66.667
    362,81.818
    364,86.792
    364,84.615
    364,67.647
    365,81.818
    367,84.615
    368,87.736
    368,82.955
    368,68.627
    370,84.615
    371,87.736
    371,82.955
    371,69.608
    373,86.538
    374,87.736
    374,70.588
    375,84.091
    377,87.736
    377,88.462
    377,71.569
    378,84.091
    380,87.736
    380,88.462
    381,84.091
    381,71.569
    383,88.462
    384,87.736
    384,84.091
    384,72.549
    386,88.462
    387,87.736
    387,84.091
    387,72.549
    389,88.462
    390,88.679
    390,84.091
    390,72.549
    392,88.462
    393,88.679
    393,72.549
    394,84.091
    396,88.679
    396,88.462
    397,84.091
    397,73.529
    399,88.462
    400,88.679
    400,84.091
    400,74.510
    402,88.462
    403,88.679
    403,84.091
    403,75.490
    405,88.462
    406,91.509
    406,75.490
    407,84.091
    408,88.462
    409,91.509
    409,75.490
    410,84.091
    412,91.509
    412,88.462
    412,75.490
    413,84.091
    415,88.462
    416,91.509
    416,86.364
    416,75.490
    418,88.462
    419,91.509
    419,76.471
    420,86.364
    421,88.462
    422,91.509
    422,76.471
    423,86.364
    424,94.231
    425,92.453
    425,76.471
    426,86.364
    428,92.453
    428,94.231
    428,78.431
    429,86.364
    431,96.154
    432,92.453
    432,86.364
    432,78.431
    434,96.154
    435,92.453
    435,86.364
    435,78.431
    437,96.154
    438,92.453
    438,78.431
    439,86.364
    440,96.154
    441,92.453
    441,78.431
    442,86.364
    443,98.077
    444,78.431
    445,93.396
    445,88.636
    447,98.077
    448,93.396
    448,88.636
    448,78.431
    450,98.077
    451,94.340
    451,88.636
    451,78.431
    453,98.077
    454,94.340
    454,79.412
    455,89.773
    456,98.077
    457,80.392
    458,94.340
    458,89.773
    459,98.077
    460,81.373
    461,94.340
    461,89.773
    463,98.077
    463,81.373
    464,94.340
    464,89.773
    466,98.077
    467,94.340
    467,89.773
    467,81.373
    469,100.000
    470,94.340
    470,81.373
    471,89.773
    472,100.000
    473,94.340
    473,81.373
    474,89.773
    475,100.000
    476,82.353
    477,94.340
    477,89.773
    479,100.000
    479,82.353
    480,94.340
    480,89.773
    482,100.000
    483,94.340
    483,89.773
    483,83.333
    485,100.000
    486,94.340
    486,92.045
    486,86.275
    488,100.000
    489,94.340
    489,86.275
    490,92.045
    491,100.000
    492,86.275
    493,94.340
    493,92.045
    494,100.000
    495,86.275
    496,94.340
    496,92.045
    498,100.000
    498,86.275
    499,94.340
    499,92.045
    501,100.000
    502,95.283
    502,92.045
    502,86.275
    504,100.000
    505,96.226
    505,86.275
    506,92.045
    507,100.000
    508,86.275
    509,97.170
    509,92.045
    510,100.000
    511,86.275
    512,97.170
    512,92.045
    514,100.000
    514,86.275
    515,97.170
    515,92.045
    517,100.000
    518,97.170
    518,92.045
    518,86.275
    520,100.000
    521,98.113
    521,86.275
    522,92.045
    523,100.000
    524,98.113
    524,86.275
    525,92.045
    526,100.000
    527,87.255
    528,100.000
    528,92.045
    530,100.000
    530,88.235
    531,100.000
    531,92.045
    533,100.000
    534,100.000
    534,93.182
    534,89.216
    536,100.000
    537,100.000
    537,93.182
    537,89.216
    539,100.000
    540,100.000
    540,89.216
    541,96.591
    542,100.000
    543,89.216
    544,100.000
    544,100.000
    545,100.000
    546,90.196
    547,100.000
    547,100.000
    549,100.000
    549,91.176
    550,100.000
    550,100.000
    552,100.000
    553,100.000
    553,100.000
    553,91.176
    555,100.000
    556,100.000
    556,93.137
    557,100.000
    558,100.000
    559,93.137
    560,100.000
    560,100.000
    561,100.000
    562,93.137
    563,100.000
    563,100.000
    565,100.000
    565,94.118
    566,100.000
    566,100.000
    568,100.000
    569,100.000
    569,100.000
    569,94.118
    571,100.000
    572,100.000
    572,94.118
    573,100.000
    574,100.000
    575,100.000
    575,98.039
    576,100.000
    577,100.000
    579,100.000
    579,100.000
    579,98.039
    581,100.000
    582,100.000
    582,100.000
    582,98.039
    584,100.000
    585,100.000
    585,100.000
    585,98.039
    587,100.000
    588,100.000
    588,100.000
    588,98.039
    590,100.000
    591,100.000
    591,100.000
    592,100.000
    593,100.000
    594,100.000
    595,100.000
    595,100.000
    596,100.000
    598,100.000
    598,100.000
    598,100.000
    600,100.000


    Thanks, and any insights would be great, for I've been stumped, and I really need this to work.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    What I find strange about this error is that it seems to show up AFTER everything is done.
    Not so strange actually.
    One of the frustratingly difficult things about tracking down access violations is that they do not
    show up at the moment you create the problem, they only show up when you try to
    access the memory that is no longer valid. Which may be much later.

    I assume that at some point in time after your Done you are trying to access an object that no longer exists.
    You might be trying to access an object that does not exist in the context from which you are trying to access it.
    e.g. Trying to free an object an object that has already been freed or never created.

    Hope this helps you to, at least, understand why it occurs when it does.

    TVal_array
    You do not tell us what that is.
    Judging by the fact that you use setLength on it I am guessing it is a Dynamic Array type.
    If that is true, you should not be setting them all to nil.
    You have two options.
    1. Do nothing. They are reference counted like strings and will be destroyed
    by Delphi when they go out of scope.
    2. Set their length to 0.

    Clive
    Last edited by clivew; August 20th, 2012 at 07:49 PM. Reason: Added Array information
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0
    Thanks, Clive. What I meant was that there was nothing for it to access after it gave the "Done" message, and that is why I thought it was strange.

    By the way, you are right - TVal_Array is a dynamic array. I thought I needed to free the memory just as in the case of a TStringList. In any case, I have commented all the commands where I free them, and am still getting the same error. I also, for good measure, setlength to 0 for all of them, and still get the same error.

    Another odd thing - and hopefully, this is a clue - is that when I step over the lines (F8), I do not get the access violation. It dutifully goes to the last command (the Done line) and then simply stops and does nothing more - no error messages. It has output whatever was meant to be output. If I try to "run" the program from the GUI though, it comes up with the access violation after the Done message! Why would this happen?

    I am happy to send any part of or the entire code, but feel that that would be imposing a lot!
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    Sorry to keep asking basic questions but...

    How do you "run" it from the GUI?
    Is it strictly as it looks - the click of a button?
    Nothing before and nothing after.

    Is there any chance that a final CR/LF at the end of the input file is giving you an
    empty ghost row that is throwing things off?

    Compiler options:
    Are IO checking; Overflow checking; Range checking; - all TRUE (checked).

    Are you doing a complete build rather than a simple compile between runs?

    What version of Delphi are you using?
    Do you have a budget for any additional tools?

    Clive
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0
    Thanks Clive. I don't mean to be coy with the code. I will be happy to reveal all of it. It's really a very basic, simple program - and that's what is so frustrating about it. Please see answers below:

    Originally Posted by clivew
    Sorry to keep asking basic questions but...

    How do you "run" it from the GUI?
    Is it strictly as it looks - the click of a button?
    Nothing before and nothing after.
    As far as I know, it is a simple click of a button...


    Is there any chance that a final CR/LF at the end of the input file is giving you an
    empty ghost row that is throwing things off?
    No, I checked.


    Compiler options:
    Are IO checking; Overflow checking; Range checking; - all TRUE (checked).
    Not sure exactly what you mean by "are they all true?" I'm not getting any I/O or overflow or range check errors. The only error I'm getting is the access violation.


    Are you doing a complete build rather than a simple compile between runs?
    I have tried both - Shift + F9 and Ctrl + F9. Same problem.

    What version of Delphi are you using?
    I use Delphi XE in the Embarcadero RAD XE suite of programs

    Do you have a budget for any additional tools?
    I do have some funds. Ideally, I would like to be able to attend some Delphi classes. Are any available?

    Again, I'd be happy to post my code here, but apaprently I'm too new to post attachments.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    Not sure exactly what you mean by "are they all true?" I'm not getting any I/O or overflow or range check errors.
    In the compiler settings you can turn checking for these errors on or off.
    If off then they will be ignored and you will not know anything is amiss until the application crashes.
    Your situation?
    If on then they will be checked all the time and you will be alerted if they occur.

    If you are using XE you may have some tools that might help like AQTime?

    I like MadExcept from Madshi, it is great for analyzing most errors.
    I am not sure what it costs or whether they have a free version for non-commercial use.
    http://madshi.net

    Clive
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0
    Originally Posted by clivew
    In the compiler settings you can turn checking for these errors on or off.
    If off then they will be ignored and you will not know anything is amiss until the application crashes.
    Your situation?
    If on then they will be checked all the time and you will be alerted if they occur.

    If you are using XE you may have some tools that might help like AQTime?
    You may have something here. I ran it using AQTime and got a report that gave a "Hit Count" of 1 for every routine except for one, which had a hit count of 1480!

    Also, the compiler gave me the following warning about this routine: "[DCC Warning] HillSlope.pas(415): W1050 WideChar reduced to byte char in set expressions. Consider using 'CharInSet' function in 'SysUtils' unit."

    If you don't mind I will reproduce this routine here, for I do not understand this warning:

    PHP Code:
    //check if non-numerical (alphabets) are in the data
    procedure THillSlopeRegr.CheckForAlphaInArray(IintegerSstring);
    var
      
    Jinteger;
      
    Chrchar;
      const 
    Numeric = ['0'..'9''.'];
    begin
      
    for := 1 to Length(S) do
      
    begin
        Chr 
    := S[J];
        if 
    Chr in Numeric then continue else
        
    begin
          MessageDlg
    ('Error!  Your file has non-numerical data in row #' IntToStr(I) + '!'mtError, [mbAbort], 0);
          Exit;
        
    end
      end
    ;
    end



    I like MadExcept from Madshi, it is great for analyzing most errors.
    I am not sure what it costs or whether they have a free version for non-commercial use.
    http://madshi.net

    Clive
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    W1050 WideChar reduced to byte char in set expressions.
    The WideChar (Unicode 2 bytes) Chr is being reduced to an AnsiChar for the set comparison.
    Use the CharInSet function (instead of in) to keep everything in Unicode.

    If you are not handling strings correctly (Unicode by default in XE)
    then there are additional possibilities for errors if any of your code
    relies on the characters in any strings being only one byte each.

    Clive
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0
    Thanks, Clive. I made the changes and I'm sure it improved the code, but that wasn't the problem, unfortunately. As far as I can see, there are no other instances where I use single bytes for characters in strings or otherwise (or i should say, at least the compiler seems happy). I have no errors or warnings from the compiler.

    So I seem to be back to Square 1. Any suggestions on how to debug in situations like this?

    llaama2012
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    So I seem to be back to Square 1. Any suggestions on how to debug in situations like this?
    Other than investing in some tools to help it is hard to say.

    One suggestion would be to take your sub-routines and, one by one, replace them with
    some hard coded result until, when you run the code, you do not get the AV.
    Then you know where to look.

    Conversely, you could start by commenting everything out then adding bits back, one by one until the AV occurs.

    e.g.
    Stage 1.
    Code:
    procedure THillSlopeRegr.ComputeCmdBtnClick(Sender: TObject);
    var
    I, K, NumValues: integer;
    EstimatedValues: string;
    EC50, HillSlope, SumSqDevX, SumSqDevY, SumCrossProds, SumSqDev_YX, MnSumSqDev_YX: double;
    InputFile: TStringList;
    X_Array, Y_Array, YHat_Array, SqDevX_Array, SqDevY_Array, CrossProds_Array, SD_YX_Array, CILL_Array, CIUL_Array, SENewY_Array, PILL_Array, PIUL_Array: TVal_Array;
    MyFile: TextFile;
    const Letters = ['A'..'Z', 'a'..'z'];
    begin
    {All code commented out}
    end;
    Stage 2.
    Code:
    procedure THillSlopeRegr.ComputeCmdBtnClick(Sender: TObject);
    var
    I, K, NumValues: integer;
    EstimatedValues: string;
    EC50, HillSlope, SumSqDevX, SumSqDevY, SumCrossProds, SumSqDev_YX, MnSumSqDev_YX: double;
    InputFile: TStringList;
    X_Array, Y_Array, YHat_Array, SqDevX_Array, SqDevY_Array, CrossProds_Array, SD_YX_Array, CILL_Array, CIUL_Array, SENewY_Array, PILL_Array, PIUL_Array: TVal_Array;
    MyFile: TextFile;
    const Letters = ['A'..'Z', 'a'..'z'];
    begin
    InputFile := TStringList.Create;
      try
        InputFile.LoadFromFile(OpenFileEditBx.Text);
    
      finally
        InputFile.Free;
      end;
    end;
    Etc. etc.
    Tedious; but probably effective.

    Clive
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    23
    Rep Power
    0
    You're right - tedious, but probably effective. Especially since I have wasted more than a week on this!

    Thanks.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo