나는 매개 변수로 tform을 사용하여 dll을 만들고 싶습니다. 간단한 계획은 해당 형식이 dll에 전달 된 경우 구성 요소 이름을 포함하는 dll 파일 반환 배열입니다.TForm을 DLL에 매개 변수로 전달하려면 어떻게해야합니까?
매개 변수로 tform을 전달할 수 있습니까?
나는 매개 변수로 tform을 사용하여 dll을 만들고 싶습니다. 간단한 계획은 해당 형식이 dll에 전달 된 경우 구성 요소 이름을 포함하는 dll 파일 반환 배열입니다.TForm을 DLL에 매개 변수로 전달하려면 어떻게해야합니까?
매개 변수로 tform을 전달할 수 있습니까?
대부분 프로세스의 VCL 인스턴스가 두 개 있는데 하나는 호스트 exe이고 다른 하나는 DLL입니다. 그리고 그것은 하나의 인스턴스가 너무 많습니다. 호스트 exe의 TForm 클래스는 DLL의 TForm 클래스와 다른 클래스입니다.
기본 규칙은 모든 모듈이 VCL/RTL 런타임의 동일한 인스턴스를 사용하지 않는 한 모듈 경계에서 VCL/RTL 객체를 공유 할 수 없다는 것입니다. 그렇게하는 방법은 패키지를 사용하여 VCL/RTL에 연결하는 것입니다.
는 두 가지 유형 선언 :
난 당신이 폼에 잇는 TMemo이 프레임 워크를 가정합니다
type
PTform = ^TForm;
TStringArray = array of string;
을하고 EXE와 DLL
모두이 볼 수 있도록.DPR 구현 섹션 :
procedure dllcomplist(p_pt_form : PTForm;
var p_tx_component : TStringArray);
stdcall;
external 'dllname.dll';
...
var
t_tx_component : TStringArray;
t_ix_component : integer;
...
Memo1.Lines.Add('Call DLL to return componentlist');
dllcomplist(pt_form,t_tx_component);
Memo1.Lines.Add('Result in main program');
for t_ix_component := 0 to pred(length(t_tx_component)) do
Memo1.Lines.Add(inttostr(t_ix_component) + '=' + t_tx_component[t_ix_component]);
setlength(t_tx_component,0);
과 DLL의 .DPR
에서
...procedure dllcomplist(p_pt_form : PTForm;
var p_tx_component : TStringArray);
stdcall;
var
t_ix_component : integer;
t_ix_memo : integer;
t_tx_component : TStringArray;
begin with p_pt_form^ do begin
setlength(t_tx_component,componentcount);
setlength(p_tx_component,componentcount);
for t_ix_component := 0 to pred(componentcount) do
begin
t_tx_component[t_ix_component] := components[t_ix_component].Name;
p_tx_component[t_ix_component] := components[t_ix_component].Name;
if components[t_ix_component].ClassName = 'TMemo' then
t_ix_memo := t_ix_component;
end;
Tmemo(components[t_ix_memo]).lines.add('Within DLL...');
for t_ix_component := 0 to pred(componentcount) do
Tmemo(components[t_ix_memo]).lines.add(inttostr(t_ix_component) + ' '
+ t_tx_component[t_ix_component]);
Tmemo(components[t_ix_memo]).lines.add('DLL...Done');
setlength(t_tx_component,0);
end;
end;
...
exports dllcomplist;
{OK -이 길이다. 엄격히 요구되는 것보다 복잡합니다. 제가 그 호출자에 결과를 표시하는 DLL에 채우는 호출 프로그램의 동적 배열을 구축하고하고있어
AND
는 DLL에 잇는 TMemo 검출하고 동일한 동적로부터 데이터를 쓰는 배열에있는 DLL에서 TMemo 호출자에서 - 데이터가 동일하다는 것을 보여주기 위해
당신은 DLL.TForm이 EXE.TForm과 다르다는 사실을 언급하지 않았다. 그것은 극복 할 수없는 것입니다. –
안녕하세요 david, 내 질문으로 구성 요소 목록 작업을 오류없이 가져올 수 있지만 "같이"Tsomecomponent 같이 구성 요소를 할당하는 경우 오류가 발생합니다 . 나는 아직도 그것에 대해 혼란 스럽다. – AsepRoro