Home > Back-end >  Encapsulation Dll problem
Encapsulation Dll problem

Time:10-17

I now want to encapsulate the unit of database operations, but want to encapsulate functional unit with three layers structure, the control transfer in assignment
For example: the function GetDataList (DBGrid: TDBGrid; QryCon: Res_QryCondition; The out PageCount: Integer; PageNum: Integer) : String;

Now I will seal the functions into a DLL pointer errors,
Excuse me what method can make the unit packaged into a DLL

thank you

CodePudding user response:

In the DLL encapsulated objects restrictions:
1) call DLL applications can only use the DLL object, the method of dynamic binding of
2) DLL encapsulation object instance can only be created in the DLL,
3) in the DLL and call DLL application need to encapsulate objects and the called method statement,

CodePudding user response:

1: you can encapsulate data source control, such as ADOQuery, don't wrap DBGrid in
2: return values do not use the string, use PChar

CodePudding user response:

Also can consider the enclosed into BPL library

CodePudding user response:

refer to the second floor feiba7288 response:
1: you can encapsulate data source control, such as ADOQuery, don't wrap DBGrid in
2: return values do not use the string, use PChar

Then I returned to a data set, and a lot of data also can't use a pchar can I still want to dbgrid assignment what method

CodePudding user response:

DLL export object, object to create within the DLL, the other should be passed a pointer,

CodePudding user response:

If you just give the Delphi call, suggest you use BPL, in order to achieve maximum flexibility, DLL that game must not,

CodePudding user response:

refer to 6th floor truexf response:
if you just give the Delphi call, suggest you use BPL, in order to achieve maximum flexibility, DLL that game definitely no,


reference 5 floor omagic reply:
DLL export object, the object need to be created within the DLL, the other should be passed a pointer,

Before I wrote the other methods such as saving or normal now suddenly invalid class typecast error,
But the effect also realized this is the reason why,

CodePudding user response:

 
//DLL

USES the
SysUtils, Windows and Dialogs,
Classes;

Type

TRec=record
S: a string [255].
end;

PRec=^ TRec;
{$R *. Res}

Procedure Doit (sIn: Pointer; SOut: Pointer); Stdcall;
The begin
ShowMessage (PRec (sIn). ^ s);
PRec (sOut) ^. S:='hello China.';
end;

Exports Doit.

The begin

End.



//main program

Procedure Doit (sIn: Pointer; SOut: Pointer); Stdcall; External 'Project1. DLL';

Implementation

{$R *. DFM}

Procedure TForm1. FormCreate (Sender: TObject);
Var
PIn, pOut: PRec;
The begin
Try
GetMem (pIn, Sizeof (TRec));
GetMem (pOut, Sizeof (TRec));
PIn ^. S:='hello world.';
Doit (pIn, pOut);
ShowMessage (pOut ^. S);
The finally
FreeMem (pIn);
FreeMem (pOut);
end;
end;





All operations are using pointer, in object, is also a pointer,

CodePudding user response:

The main program must also state structure,

CodePudding user response:

It is recommended to use call interface mode

CodePudding user response:

Mark, can use later

CodePudding user response:

  • Related