[fpc-pascal] Clueless here

Darius Blaszijk dhkblaszyk at zeelandnet.nl
Thu Jun 29 22:06:43 CEST 2006


Hi,

I have two overloaded functions. One overloaded function just rearanges one parameter from an array of extended to an array of ^extended and calls the other overloaded function. The problem is however that the 2nd function call crashes the app. I really have no idea why therefore I'm posting the code in the hope someone with more insight can help me here.

So what happens is the following; the first debugmessages are ok and as expected. However the second debugmessages (array of PJmFloat) crash the application. I have attached the backtrace.

Darius

type
  TJmFloat = extended;
  PJmFloat = ^TJmFloat;
  TDynTJmFloatArray = array of TJmFloat;

Function FitSession( Parameters : array of PJmFloat; ChiSquareFunc : TOFitFunc ) : IFit;
var i: integer;
begin
  //debug only
  for i := 0 to High(Parameters) do
    ShowMessage('array of PJmFloat ' + FloatToStr(Parameters[i]^));

 Result := TFit.Create( Parameters, ChiSquareFunc );
end;

function FitSession(Parameters: TDynTJmFloatArray; ChiSquareFunc: TOFitFunc): IFit;
var
  Params: array of PJmFloat;
  i: integer;
begin
  SetLength(Params, Length(Parameters));

  for i := 0 to High(Parameters) do
  begin
    Params[i] := AllocMem(SizeOf(TJmFloat));
    Params[i] := @Parameters[i];
  end;

  //debug only
  for i := 0 to High(Params) do
    ShowMessage('TDynTJmFloatArray ' + FloatToStr(Params[i]^));

  Result := FitSession(Params, ChiSquareFunc);
end;

begin
    SetLength(c, 2);
    c[0] := 2;
    c[1] := 0.2;
    Fit := FitSession(c, @ChiSquareFunc);
end;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20060629/4f388216/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: backtrace.zip
Type: application/x-zip-compressed
Size: 1993 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20060629/4f388216/attachment.bin>


More information about the fpc-pascal mailing list