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