Darius Blaszijk wrote: > 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];
Don't you want to write here 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; > > _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal