안녕하세요...질문 좀 드릴려고...
Access Violation Error라고 뜨는데요...
코딩 좀 봐 주세요...
--- Function을 지정한 유닛
unit Unit13;
interface
type
Pdbl = ^double;
function imsls_d_regression(a, e : integer; b,c : pdbl; f:integer ; g: pdbl ; h : integer; i : pdbl ; j : integer; k : pdbl ; d : integer) : pdbl; stdcall;
external 'cstat.dll';
procedure regression(N : integer; x, y, w, a, d : pdbl);
implementation
procedure regression(N : integer; x, y, w, a, d : pdbl);
var
imsls_anova_table_user, imsls_weights : integer ;
IMSLS_RETURN_USER : integer ;
p : pdbl;
begin
imsls_anova_table_user := 10090 ;
imsls_weights := 15400 ;
IMSLS_RETURN_USER := 14280 ;
p := imsls_d_regression(N, 1, x, y, IMSLS_WEIGHTS, w,
IMSLS_ANOVA_TABLE_USER, a ,
IMSLS_RETURN_USER, d, 0);
end;
end.
--- 에러가 발생하는 부분
procedure TForm11.Button3Click(Sender: TObject);
var
x : array[0..600] of double;
y : array[0..600] of double;
a : array[0..14] of double;
d : array[0..1] of double;
w : array[0..600] of double;
i, N_OBSERVATIONS : integer ;
po : single ;
p : pchar;
result : string ;
begin
adoquery1.close ;
adoquery1.Parameters[0].Value := edit1.Text ;
adoquery1.Parameters[1].Value := edit2.Text ;
adoquery1.Parameters[2].Value := label7.Caption ;
adoquery1.Prepared := true ;
adoquery1.Open ;
N_OBSERVATIONS := adoquery1.RecordCount ;
for i := 0 to 599 do
begin
x[i] := 0 ;
y[i] := 0 ;
w[i] := 0 ;
end;
adoquery1.First ;
for i := 0 to N_OBSERVATIONS -1 do
begin
x[i] := adoquery1.Fields[2].Value ;
y[i] := adoquery1.Fields[1].Value ;
adoquery1.Next ;
end ;
adoquery1.close ;
po := 0.0 ;
for i := 0 to N_OBSERVATIONS -1 do
begin
w[i] := 1.0 ;
end ;
regression(N_OBSERVATIONS, @x, @y, @w, @a[0], @d[0]);
-- showmessage를 하면 제대로 값이 나옵니다...
showmessage( floattostr(d[1]));
-- result변수에 값을 넘기면 값이 제대로 넘어값니다...
result := floattostr(d[1]) ;
-- 컴포넌트에 뿌릴려고 하면 값이 안나옵니다... 충돌에러가 발생하는 부분입니다...
label1.caption := result ;
end;
> 안녕하세요...질문 좀 드릴려고...
>
> Access Violation Error라고 뜨는데요...
>
> 코딩 좀 봐 주세요...
>
> --- Function을 지정한 유닛
> unit Unit13;
>
> interface
>
>
> type
> Pdbl = ^double;
>
> function imsls_d_regression(a, e : integer; b,c : pdbl; f:integer ; g: pdbl ; h : integer; i : pdbl ; j : integer; k : pdbl ; d : integer) : pdbl; stdcall;
>
> external 'cstat.dll';
> procedure regression(N : integer; x, y, w, a, d : pdbl);
>
>
>
> implementation
>
> procedure regression(N : integer; x, y, w, a, d : pdbl);
> var
> imsls_anova_table_user, imsls_weights : integer ;
> IMSLS_RETURN_USER : integer ;
> p : pdbl;
> begin
>
> imsls_anova_table_user := 10090 ;
> imsls_weights := 15400 ;
> IMSLS_RETURN_USER := 14280 ;
>
> p := imsls_d_regression(N, 1, x, y, IMSLS_WEIGHTS, w,
> IMSLS_ANOVA_TABLE_USER, a ,
> IMSLS_RETURN_USER, d, 0);
>
> end;
>
>
> end.
>
>
> --- 에러가 발생하는 부분
> procedure TForm11.Button3Click(Sender: TObject);
> var
> x : array[0..600] of double;
> y : array[0..600] of double;
> a : array[0..14] of double;
> d : array[0..1] of double;
> w : array[0..600] of double;
> i, N_OBSERVATIONS : integer ;
> po : single ;
> p : pchar;
> result : string ;
>
> begin
>
> adoquery1.close ;
> adoquery1.Parameters[0].Value := edit1.Text ;
> adoquery1.Parameters[1].Value := edit2.Text ;
> adoquery1.Parameters[2].Value := label7.Caption ;
> adoquery1.Prepared := true ;
> adoquery1.Open ;
>
> N_OBSERVATIONS := adoquery1.RecordCount ;
>
> for i := 0 to 599 do
> begin
> x[i] := 0 ;
> y[i] := 0 ;
> w[i] := 0 ;
> end;
>
> adoquery1.First ;
> for i := 0 to N_OBSERVATIONS -1 do
> begin
> x[i] := adoquery1.Fields[2].Value ;
> y[i] := adoquery1.Fields[1].Value ;
> adoquery1.Next ;
> end ;
> adoquery1.close ;
>
> po := 0.0 ;
> for i := 0 to N_OBSERVATIONS -1 do
> begin
> w[i] := 1.0 ;
> end ;
>
>
> regression(N_OBSERVATIONS, @x, @y, @w, @a[0], @d[0]);
>
> -- showmessage를 하면 제대로 값이 나옵니다...
> showmessage( floattostr(d[1]));
>
> -- result변수에 값을 넘기면 값이 제대로 넘어값니다...
> result := floattostr(d[1]) ;
>
> -- 컴포넌트에 뿌릴려고 하면 값이 안나옵니다... 충돌에러가 발생하는 부분입니다...
> label1.caption := result ;
>
>
> end;
>
참고: result는 예약된 것 같습니다.
result를 다른이름으로 바꾸어서 실행해 보세요.