If I understood your question correctly, you can do it, here is one way to do it:
testdll.dll
library TestDll; uses SysUtils, Classes, uCommon in 'uCommon.pas'; {$R *.res} procedure TakeMyFancyRecord(AMyFancyRecord: PMyFancyRecord); stdcall; begin AMyFancyRecord^.DoSomething; end; exports TakeMyFancyRecord name 'TakeMyFancyRecord'; begin end.
uCommon.pas <- used by both the application and the dll, the unit in which your fantastic entry is defined
unit uCommon; interface type PMyFancyRecord = ^TMyFancyRecord; TMyFancyRecord = record Field1: Integer; Field2: Double; procedure DoSomething; end; implementation uses Dialogs; { TMyFancyRecord } procedure TMyFancyRecord.DoSomething; begin ShowMessageFmt( 'Field1: %d'#$D#$A'Field2: %f', [ Field1, Field2 ] ); end; end.
and finally, the test application, the application file β new β vcl forms, release the button in the form, include uCommon.pas in the uses clause, add a link to the external method
procedure TakeMyFancyRecord(AMyFancyRecord: PMyFancyRecord); stdcall; external 'testdll.dll' name 'TakeMyFancyRecord';
and in the button on the click event add
procedure TForm1.Button1Click(Sender: TObject); var LMyFancyRecord: TMyFancyRecord; begin LMyFancyRecord.Field1 := 2012; LMyFancyRecord.Field2 := Pi; TakeMyFancyRecord( @LMyFancyRecord ); end;
RENOUNCEMENT:
- works in D2010;
- compiles on my machine!
enjoy it!
David Heffernan's edit
To be 100% understandable, the DoSomething method that is executed is the method defined in the DLL. The DoSomething method defined in EXE is never executed in this code.
source share