Mam taki kod:
procedure AddPlugin(Name: PChar);
var
DLL: THandle;
QueryFunctions: procedure(var MFun, PFun: PFunctions);
QueryPluginName: procedure(var Name: PChar);
MFun, PFun: PFunctions;
PlName: PChar;
i, j: Byte;
begin
DLLCount:=DLLCount+1; // Temporary
DLL:=LoadLibrary(Name);
try
@QueryPluginName:=GetProcAddress(DLL, 'QueryPluginName');
if not (@QueryPluginName = nil) then begin
QueryPluginName(PlName);
@QueryFunctions:=GetProcAddress(DLL, 'QueryFunctions');
if not (@QueryFunctions = nil) then begin
j:=Plugins.Add(Name);
New(MFun);
New(PFun);
QueryFunctions(MFun, PFun);
With MFun^ do begin // <-- Tu wywala Acces Violation, przynajmniej tak pokazuje
If Count>0 then begin
SetLength(PluginsMenu, Plugins.Count);
PluginsMenu[j].MainObject:=TMenuItem.Create(MainFrm.MMPlugins);
PluginsMenu[j].MainObject.Caption:=PlName;
MainFrm.MMPlugins.Add(PluginsMenu[j].MainObject);
For i:=0 to Count-1 do begin
SetLength(PluginsMenu[j].SubItems, Count);
PluginsMenu[j].SubItems[i]:=TMenuItem.Create(PluginsMenu[j].MainObject);
PluginsMenu[j].SubItems[i].Caption:=Strings[i];
PluginsMenu[j].SubItems[i].OnClick:=MainFrm.MFunExecute;
end;
end;
end;
With PFun^ do begin
end;
Dispose(MFun);
Dispose(PFun);
end;
end;
finally
FreeLibrary(DLL);
end;
end;
I przy With MFun do begin wywala Acces Violation. (PFunctions=TFunctions, TFunctions=TStringList). Co może być źle?
[dopisane]
Hmm... Doszedłem, że błąd jest gdzie indziej, niż pokazywał to Delphi.
Wywala go przy takiej procedurze:
Procedure QueryFunctions(var MFun, PFun: PFunctions); stdcall;
begin
PFun^:=TStringList.Create; // <-- tutaj
PFun^.BeginUpdate; // <-- albo tutaj jest Acces Violation
With PFun^ do begin
Add('Mail :: Send e-mail');
end;
PFun^.EndUpdate;
MFun^:=TStringList.Create;
MFun^.BeginUpdate;
With MFun^ do begin
Add('About');
Add('Setup');
Add('Receive');
end;
MFun^.EndUpdate;
end;