unit uTools;
interface
uses Windows, Forms, Dialogs, SysUtils, ShellAPI;
type
TCallBack =
procedure(iMsg: Integer;
var sMessage: PChar);
TDLLCall =
procedure(
const Callback: TCallBack);
THandle = integer;
type
TAlphaCodeTool =
class
private
fFileName:
String;
fParameter:
String;
public
property filename:
string read fFileName
write fFileName;
property parameter:
string read fParameter
write fParameter;
constructor Create(Filename, Param:
string);
procedure CallTool(
const Callback: TCallback);
procedure DLL_CallBack(iMsg: Integer;
var sMessage: PChar);
procedure Execute_Tool;
end;
const
REQUEST_ACTIVE_DOCUMENT_TEXT = 1;
REQUEST_ACTIVE_DOCUMENT_FILENAME = 2;
SET_ACTIVE_DOCUMENTS_TEXT = 3;
SET_EDITORMOD = 4;
OPERATION_LOAD_DOCUMENT = 5;
OPERATION_LOAD_DOCUMENT_W = 6;
REQUEST_USER_STRING = 10;
implementation
constructor TAlphaCodeTool.Create(FileName, Param:
String);
begin
self.filename := filename;
self.parameter := param;
end;
procedure TAlphaCodeTool.CallTool(
const Callback: TCallback);
var
Handle: THandle;
Call: TDLLCall;
begin
Handle := LoadLibrary(PChar(filename));
if Handle <> 0
then
begin
@Call := GetProcAddress(
Handle, '
CallDLL');
if @Call <>
nil then
Call(CallBack);
FreeLibrary(
Handle);
end;
end;
procedure TAlphaCodeTool.DLL_CallBack(iMsg: Integer;
var sMessage: PChar);
begin
case iMsg
of
REQUEST_USER_STRING:
begin
sMessage := PCHAR(InputBox(FileName, '
Bitte Wert eingeben', '
'));
end;
end;
end;
procedure TAlphaCodeTool.Execute_Tool;
begin
if AnsiLowerCase(ExtractFileExt(FileName)) = '
.dll'
then
CallTool(DLL_CallBack)
else // <-- Fehlermeldung hier: Inkompatible Typen: Reguläre Prozedur und Methodenzeiger.
ShellExecute(0, '
open', @filename, @parameter,
nil, SW_SHOWNORMAL);
end;
end.