Der Code ist zum besseren Verständnis vereinfacht.
Muss ich tatsächlich für jede externe Funktion/Prozedur einen eigenen Typ definieren, auf den ich dann caste? Also z.B. "mysql_get_client_info := Tmysql_get_client_info(GetProcAddress(...))" ?
Code: Alles auswählen
type
TMyLib = class(TObject)
mysql_get_client_info: function: PAnsiChar; stdcall;
mysql_get_server_info: function(Handle: PMYSQL): PAnsiChar; stdcall
private
FHandle: TLibHandle;
protected
procedure AssignProc(var Proc: Pointer; Name: PAnsiChar);
public
constructor Create(DllFile);
end;
...
constructor TMyLib.Create(DllFile: String);
begin
inherited Create;
FHandle := LoadLibrary(DllFile);
AssignProc(@mysql_get_client_info, 'mysql_get_client_info'); <<< Error: Can't assign values to an address
AssignProc(@mysql_get_server_info, 'mysql_get_server_info');
...
end;
procedure TMyLib.AssignProc(var Proc: Pointer; Name: PAnsiChar);
begin
Proc := GetProcAddress(FHandle, Name);
end;
Das ändert den Compiler-Modus zu "Turbo Pascal". Ändert aber nichts an dem Compiler-Fehler...Error: Can’t assign values to an address
It is not allowed to assign a value to an address of a variable, constant, procedure or function. You can try compiling with -So if the identifier is a procedure variable.