بسم الله الرحمن الرحيم
عندى مشكلة عند كومبيل لكتابة دالة الكود بالكامل
كود :
library test;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes,
dialogs;
{$R *.res}
procedure bsp-msg(caption :string);stdcall;export;
begin
ShowMessage(caption);
End;
exports
bsp-msg;
begin
end.
الخطأ هنا procedure bsp-msg(caption tring);stdcall;export;
تفاصيل[COLOR="red"]
[Error] test.dpr(19): ';' expected but '-' found
[Error] test.dpr(21): Undeclared identifier: 'caption'
[Error] test.dpr(24): ',' or ';' expected but '-' found [/COLOR]
والبروجيكت فى المرفقات
السبب أنك تحاول أن تقوم بعمل تنفيذ / تشغيل للمكتبة Dll و ليس التطبيق exe .
قم بالتحقق من المشروع الحالي .
+ هل قرأت ال comment أعلى المكتبة :
كود :
{ Important note about DLL memory management: [COLOR="Red"]ShareMem must be the
first unit in your library's USES[/COLOR] clause AND your project's (select
Project-View Source) USES clause[COLOR="red"] if your DLL exports any procedures or
functions that pass strings as parameters or function results[/COLOR]. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. [COLOR=Blue]To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. [/COLOR]}
نصيحة : تجنب استخدام صنف String في ال dll ..
كبديل استخدم PChar .
أخى الكريم SMP3 شكرا لمرورك :.
أنا احاول ابتدى اكتب دالة من صنعى واستعنت بأحد الكتب وطبقت كما موجود بالشرح ممكن فضلا وليس امراّ تعمل مقارنة ما بين الشرح والمشروع الخاص بى لان الشرح وصل الى ربط dll بالمشروع عموما البروجيت المرفقات
procedure bsp_msg(caption: PChar); stdcall; export; begin ShowMessage(Caption); end;
exports bsp_msg;
begin
end.
كما قلت لك سابقا لا تستخدم الصنف String مع dll ..
---------------------------- هذا التطبيق الذي يستدعي المكتبة :
PHP كود :
procedure bsp_msg(Caption: PChar); stdcall;external 'test.dll' name 'bsp_msg';
procedure TForm1.FormCreate(Sender: TObject); begin bsp_msg('Hi..'); end;
----------------------------------------- عندما تعمل على ربط مكتبة dll مع تطبيق خارجي عليك مراعاة عدة أشياء , أهمها :
-أن تتجنب استخدام الصنف String,AnsiString,WideString.
-أن تحترم ال calling convention . في مثالك : stdcall : يجب أن تكون نفسها الموجودة في تعريف الدالة .
-يجب أن يكون اسم الدالة Valid أي لا يحتوي على نقاط و فواصل و - ؟ / ...
-تحقق من أن المكتبة موجودة في نفس مجلد التطبيق exe .