SRL Archive - Help and Support

TPAs in plugin


bg5

2012-06-01 12:03:22

Can someone give me example ,how to use TPA in plugin? At http://docs.wizzup.org/simba/simbaref/plugins.html there is template ,I added basic TPA function ,but what I get from it is accedd violation. This is my code:
{ Example based upon the SPS Plugin }
library project3;

{$mode objfpc}{$H+}

{$macro on}
{$define callconv:=
{$IFDEF WINDOWS}{$IFDEF CPU32}cdecl;{$ELSE}{$ENDIF}{$ENDIF}
{$IFDEF LINUX}{$IFDEF CPU32}cdecl;{$ELSE}{$ENDIF}{$ENDIF}
}

uses
classes, sysutils, math
{ you can add units after this };

var
OldMemoryManager: TMemoryManager;
memisset: Boolean = False;


type T3DIntegerArray = array of array of array of integer;
type TPointArray = array of TPoint;

function HelloTPA(tpa :TPointArray) : TPointArray; callconv
var
a,h : integer;
begin
h := high(tpa);
SetLength(Result,h+1);
for a := 0 to h do
Result[a].x := tpa[a].x +5;
end;

function HelloPlugin(s: String): String; callconv
begin
result := s;
end;

function GetPluginABIVersion: Integer; callconv export;
begin
Result := 2;
end;

procedure SetPluginMemManager(MemMgr : TMemoryManager); callconv export;
begin
if memisset then
exit;
GetMemoryManager(OldMemoryManager);
SetMemoryManager(MemMgr);
memisset := true;
end;

procedure OnDetach; callconv export;
begin
SetMemoryManager(OldMemoryManager);
end;

function GetTypeCount(): Integer; callconv export;
begin
Result := 1;
end;

function GetTypeInfo(x: Integer; var sType, sTypeDef: PChar): integer; callconv export;
begin
case x of
0: begin
StrPCopy(sType, 'T3DIntegerArray');
StrPCopy(sTypeDef, 'array of array of array of integer;');
end;

else
x := -1;
end;

Result := x;
end;

function GetFunctionCount(): Integer; callconv export;
begin
Result := 2;
end;

function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): Integer; callconv export;
begin
case x of
0:
begin
ProcAddr := @HelloPlugin;
StrPCopy(ProcDef, 'function HelloPlugin(s: String): String;');
end;
1: begin
ProcAddr := @HelloTPA;
StrPCopy(ProcDef, 'function HelloTPA(tpa :TPointArray) : TPointArray;');
end;
else
x := -1;
end;

Result := x;
end;

exports GetPluginABIVersion;
exports SetPluginMemManager;
exports GetTypeCount;
exports GetTypeInfo;
exports GetFunctionCount;
exports GetFunctionInfo;
exports OnDetach;

begin
end.
Error: Exception: Access violation at line 7

masterBB

2012-06-01 12:14:57

Would it work if you add it to GetTypeInfo ?

nielsie95

2012-06-01 14:47:50

Does it work with Lape? Does it work when you change it to a var/out parameter?
What version of Simba/FPC?

bg5

2012-06-02 01:45:54

From: masterBB
Would it work if you add it to GetTypeInfo ?


I tried this also ,and error is the same.

Does it work with Lape? Does it work when you change it to a var/out parameter?
What version of Simba/FPC?


Lazarus 0.9.30.40 FPC 2.6.0

Simba is released under the GPL license.
You are currently using version: 990
Compiled with FPC version 2.4.4

Ok ,so I tested following configurations:

- PascalScript:

TPA as result:
- TPA type exported : access violation
- TPA type not exported : access violation

TPA as out parameter:
- TPA type exported : type mismatch (didn't compile)
- TPA type not exported : returns empty TPA


TPA as var parameter:
- TPA type exported : type mismatch (didn't compile)
- TPA type not exported : seems to work!

I will tell you what with Lape ,when (if ever :P ) I compile libffi.