![](/img/trans.png)
[英]Compiling projects with DCC32 as in Delphi 6 professional IDE
[英]Accessing Delphi method pointers from another unit in another package when compiling with 'dcc32 -JL'
這是一個有點復雜的場景-在實踐中甚至更加復雜,但是針對這個問題,我設法將其最小化。
我定義了兩個Delphi包:BasePackage.dpk和AnotherPackage.dpk
package BasePackage;
requires
rtl;
contains
Base in 'Base.pas';
end.
和
package AnotherPackage;
requires
BasePackage;
contains
Another in 'Another.pas';
end.
和單位
unit Base;
interface
type
TMethod = procedure;
TEncodeableType = record
Method: TMethod;
end;
PEncodeableType = ^TEncodeableType;
procedure Method_Impl;
const
TestMethod_Type: TEncodeableType = (
Method: Method_Impl;
);
implementation
procedure Method_Impl;
begin
end;
end.
和
unit Another;
interface
uses
Base;
implementation
const
ResponseType: PEncodeableType = @TestMethod_Type;
end.
一切基本上都能正常編譯,我什至可以使用'dcc32 -JPHNEK --BCB'
生成基本的C ++ Builder單元,但是當我嘗試使用'dcc32 -JPHNEK --BCB -JL'
生成C ++ Builder的庫文件時'dcc32 -JPHNEK --BCB -JL'
我得到
>dcc32 -JPHNEK --BCB -JL BasePackage.dpk
Embarcadero Delphi for Win32 compiler version 32.0
Copyright (c) 1983,2017 Embarcadero Technologies, Inc.
BasePackage.dpk(10)
11 lines, 0.09 seconds, 3688 bytes code, 176 bytes data.
>dcc32 -JPHNEK --BCB -JL AnotherPackage.dpk
Embarcadero Delphi for Win32 compiler version 32.0
Copyright (c) 1983,2017 Embarcadero Technologies, Inc.
AnotherPackage.dpk(10)
Error: E2201 Need imported data reference ($G) to access 'TestMethod_Type' from unit 'Another'
我嘗試使用不同的編譯選項(當然,將{$G+}
或{$IMPORTEDDATA ON}
引入到單元和包中(盡管這是默認設置),但是還沒有看到它們有什么不同。
這些軟件包在.cfg中不包含任何選項或具有以下選項進行編譯:
-$A+
-$B-
-$C-
-$D-
-$E-
-$F-
-$G+
-$H+
-$I-
-$J-
-$K-
-$L+
-$M-
-$N+
-$O+
-$P+
-$Q-
-$R-
-$S-
-$T+
-$U-
-$V-
-$W-
-$X+
-$Y-
-$Z1
-cg
-AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;
-H+
-W+
-M
-$M16384,1048576
-K$00300000
-Z
並且在.dpk中不包含任何選項或具有以下選項:
{$ALIGN 8}
{$ASSERTIONS ON}
{$BOOLEVAL OFF}
{$DEBUGINFO ON}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS ON}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION ON}
{$OVERFLOWCHECKS ON}
{$RANGECHECKS ON}
{$REFERENCEINFO OFF}
{$SAFEDIVIDE OFF}
{$STACKFRAMES OFF}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST ON}
{$MINENUMSIZE 1}
{$IMAGEBASE $300000}
{$DESIGNONLY}
{$IMPLICITBUILD OFF}
我是否可以進行這項工作(我真的需要其他軟件包中的功能)嗎?
我一直在用Delphi 10.2 Tokyo和XE4進行編譯,結果相同。
我相信這是一個編譯器問題,因此可能無法完全解決我的情況。 但是,我可以使用變量而不是常量來聲明映射(實際上,我有幾個內部結構)。
因此,此版本的Another.pas可以編譯並運行:
unit Another;
interface
uses
Base;
implementation
var
ResponseType: PEncodeableType;
initialization
ResponseType := @TestMethod_Type;
end.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.