Subject | Re: [ib-support] UDF + Delphi |
---|---|
Author | Andreas Prucha |
Post date | 2002-05-26T07:59:59Z |
On 25 May 2002 at 22:44, semprolbat wrote:
are usually passed by reference by default.
function ib_util_malloc(s: integer): pointer; cdecl; external 'ib_util.dll';
function udftest(i: PInteger): PChar; cdecl;
var
s: String;
begin
Result := NIL;
If i <> NIL then
begin
s := IntToStr(i^);
Result := ib_util_malloc(Length(s)+1);
StrPCopy(Result, s);
end;
end;
This should do the job.
--
Best Regards - Mit freundlichen Gruessen,
Andreas Prucha
helicon software development
> I wrote a function in delphi:Yep. IntToStr creates a AnsiString which InterBase can't handle. And the parameters
>
> function udftest(i:integer):pChar;
> begin
> result:=pChar(intToStr(i));
> end;
>
> with a corresponding
>
> declare external function udftest
> integer
> returns cstring(80) free_it
> entry_point 'udftest'
> module_name 'my_udf.dll';
>
> select udftest(1) from rdb$database; never(?) returns 1.
> I guess this is due to a memory-handling issue.
are usually passed by reference by default.
function ib_util_malloc(s: integer): pointer; cdecl; external 'ib_util.dll';
function udftest(i: PInteger): PChar; cdecl;
var
s: String;
begin
Result := NIL;
If i <> NIL then
begin
s := IntToStr(i^);
Result := ib_util_malloc(Length(s)+1);
StrPCopy(Result, s);
end;
end;
This should do the job.
--
Best Regards - Mit freundlichen Gruessen,
Andreas Prucha
helicon software development