Laex / Delphi-OpenCV-Class

Experimental Delphi binding for OpenCV 4.XX
Apache License 2.0
87 stars 26 forks source link

Exception in CppString('') as function parameter #30

Closed SerhioUser closed 1 year ago

SerhioUser commented 1 year ago

Hi Laex,

If CppString is initialized with an empty string and used as a parameter in the OPENCV functions (many default parameters), then this leads to an exception in the called functions, since the null address is passed to the constructor as a parameter. For example var s := CppString(''); raised exception.

I suggest in such cases to initialize CppString with the address of a static or global variable containing 0. For example, instead of

procedure CppString.assign(const p: pCVCHAR);
begin
{$IF not defined(PACKAGE)}
  class_virt_func_STD_BASIC_STRING_OF_CVCHAR_assign_3(Self, p);
{$IFEND}
end;

something like this:

var
 CppStringChar : AnsiChar;
procedure CppString.assign(const p: pCVCHAR);
var
 p1: pCVCHAR;
begin
{$IF not defined(PACKAGE)}
  CppStringChar := char(0);
  if p = nil then
    p1 := @CppStringChar
  else
    p1 := p;
  class_virt_func_STD_BASIC_STRING_OF_CVCHAR_assign_3(Self, p1);
{$IFEND}
end;

This is a rough decision. Maybe you can come up with something more elegant.

And a big request - make the "human_parsing" example work. (if it is possible of course). Recognition is a very necessary feature!

Thanks.

Laex commented 1 year ago

procedure CppString.assign(const p: pCVCHAR); begin {$IF not defined(PACKAGE)} if Assigned(p) then class_virt_func_STD_BASIC_STRING_OF_CVCHAR_assign_3(Self, p); {$IFEND} end;

I'm working on fixing "human_parsing", as well as other examples.