在Delphi 10 Seattle中,我可以使用以下代码来解决过于严格的可见性限制.
如何访问私有变量?
type
TBase = class(TObject)
private
FMemberVar: integer;
end;
Run Code Online (Sandbox Code Playgroud)
我如何访问普通或虚拟私有方法?
type
TBase2 = class(TObject)
private
procedure UsefullButHidden;
procedure VirtualHidden; virtual;
procedure PreviouslyProtected; override;
end;
Run Code Online (Sandbox Code Playgroud)
type
TBaseHelper = class helper for TBase
function GetMemberVar: integer;
Run Code Online (Sandbox Code Playgroud)
在Delphi 10.1 Berlin中,类助手不再能够访问主题类或记录的私有成员.
是否有其他方式可以访问私人会员?
你能帮我理解在Win32平台上我的Delphi应用程序中FPU Control Word的运行情况.
当我们创建一个新的VCL应用程序时,控制字设置为1372h.这是我不明白的第一件事,为什么它是1372h而不是1332h,这是Default8087CW在System单位中定义的.
这两者之间的区别:
1001101110010 //1372h
1001100110010 //1332h
Run Code Online (Sandbox Code Playgroud)
是根据文档保留或不使用的第6位.
第二个问题是CreateOleObject.
function CreateOleObject(const ClassName: string): IDispatch;
var
ClassID: TCLSID;
begin
try
ClassID := ProgIDToClassID(ClassName);
{$IFDEF CPUX86}
try
Set8087CW( Default8087CW or $08);
{$ENDIF CPUX86}
OleCheck(CoCreateInstance(ClassID, nil, CLSCTX_INPROC_SERVER or
CLSCTX_LOCAL_SERVER, IDispatch, Result));
{$IFDEF CPUX86}
finally
Reset8087CW;
end;
{$ENDIF CPUX86}
except
on E: EOleSysError do
raise EOleSysError.Create(Format('%s, ProgID: "%s"',[E.Message, ClassName]),E.ErrorCode,0) { Do not localize }
end;
end;
Run Code Online (Sandbox Code Playgroud)
上面的功能是将控制字改为137Ah,所以它打开第3位(溢出掩码).我不明白为什么要调用它Reset8087CW,而不是恢复进入函数之前的单词状态?
当我使用Delphi Berlin 10.1 [weak](和[unsafe])引用时,"Supports"函数和"QueryInterface"都在给定一个标有"weak"属性的接口变量时递增引用计数(与"with"相同的行为)不安全的"属性".
program WeakReferences;
{$APPTYPE CONSOLE}
{$R *.res}
uses System.SysUtils;
type
IAnInterfacedObject = interface
['{351DFDA3-42CA-4A1D-8488-494CA454FD9C}']
end;
TAnInterfacedObject = class(TInterfacedObject, IAnInterfacedObject)
protected
function GetTheReferenceCount : integer;
public
constructor Create;
destructor Destroy; override;
property TheReferenceCount : integer read GetTheReferenceCount;
end;
constructor TAnInterfacedObject.Create;
begin
inherited Create;
writeln('(create AIO instance)');
end;
destructor TAnInterfacedObject.Destroy;
begin
writeln('(destroy AIO instance)');
inherited Destroy;
end;
function TAnInterfacedObject.GetTheReferenceCount : integer;
begin
Result := FRefCount;
end;
procedure WithoutSupports;
var
AIOinstance : TAnInterfacedObject;
AIOinterfaced : IAnInterfacedObject;
[Weak]
WeakAIOinterfaced : IAnInterfacedObject; …Run Code Online (Sandbox Code Playgroud) 我想使用Gabriel Corneanu的jpegex,jpeg.TJPEGImage的类助手.阅读这个和这个,我了解到,超过德尔福西雅图你不能访问私有字段不再像jpegex确实(在下面的例子中FDATA).和David Heffernan提出的VMT一样,远远超出我的范围.有没有更简单的方法来完成这项工作?
type
// helper to access TJPEGData fields
TJPEGDataHelper = class helper for TJPEGData
function Data: TCustomMemoryStream; inline;
procedure SetData(D: TCustomMemoryStream);
procedure SetSize(W,H: integer);
end;
// TJPEGDataHelper
function TJPEGDataHelper.Data: TCustomMemoryStream;
begin
Result := self.FData;
end;
Run Code Online (Sandbox Code Playgroud) 使用最新的Delphi版本(柏林/ 10.1/24),[Ref]属性真的有必要吗?
我问这个是因为在线文档说:
常量参数可以通过值或引用传递给函数,具体取决于所使用的特定编译器.要强制编译器通过引用传递常量参数,可以将[Ref]装饰器与const关键字一起使用.
我使用REST API调用创建一个安装对象,如下所示:
curl -X POST \
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"deviceType": "ios",
"deviceToken": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
"channels": [
""
]
}' \
https://<your.parseprovider.here>/1/installations
Run Code Online (Sandbox Code Playgroud)
安装对象已创建并由响应指示:
{
"objectId": "EmqGmZXGEm",
"createdAt": "2017-02-15T10:13:18.647Z"
}
Run Code Online (Sandbox Code Playgroud)
现在假设我想更新channels字段以在安装对象中包含"foo"通道,我可以简单地发出一个调用:
curl -X PUT \
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"channels": [
"",
"foo"
]
}' \
https://<your.parseprovider.here>/1/installations/EmqGmZXGEm
Run Code Online (Sandbox Code Playgroud)
然后响应表明成功:
{
"updatedAt": "2017-02-15T10:18:31.055Z"
}
Run Code Online (Sandbox Code Playgroud)
但是,当我像这样执行PUT调用时(如在REST API文档中,请注意包含deviceType和deviceToken字段):
curl -X PUT \
-H "X-Parse-Application-Id: …Run Code Online (Sandbox Code Playgroud) 我在尝试定义嵌套通用记录时遇到了一个奇怪的编译器错误.
嵌套适用于类和接口,但不能以某种方式记录.
type
TRec<T> = record
Value: T;
end;
TCls = class
public
Rec: TRec<TRec<Integer>>;
end;
Run Code Online (Sandbox Code Playgroud)
这不是在Delphi Berlin 10.1.2上编译的,在东京10.2.3也没有运气.这是语言或编译器问题的限制吗?
错误消息是:
[dcc32错误] Project1.dpr(22):E2564未定义类型'TRec <T>'
我只想要一次嵌套Spring.Nullable<>类型,但是没有用.之后我用一个简单的通用记录快速复制了它.
我有一个COM DLL项目,我能够在Delphi 2007和XE8中调试它(在断点处停止).
但是,似乎IDE无法在Delphi 10 Seattle或10.1 Berlin的断点处停止.
我的调试步骤:
更改为DEBUG(并检查勾选的那些调试选项.例如,调试信息)
regsvr32输出目录下的项目DLL
编写一个简单地创建COM对象并调用其方法的vbscript
在调试器中,为32位或64位调试设置Run命令行c:\windows\syswow64\cscript.exec:\windows\system32\cscript.exe
设置命令行参数以运行vbscript.
在调用的方法上设置断点.
点击F9
预计:在断点处停下来
在Delphi 2007和XE8中,一切都很好,但我无法在Delphi Seattle或Berlin中完成.
什么可能出错?在Delphi的最新IDE版本下,为了调试COM DLL,是否需要启用/禁用任何设置?
德尔福柏林10.1增加了[弱]参考.Marco Cantu的博客有一些基础知识.
对于我的测试,我创建了两个包含两个自动化对象类型的COM库.容器对象包含内容对象的列表,而内容对象包含对其容器的弱引用.
以下两个方案已经过测试并正常工作(弱引用设置为null并释放内存):
但是,当我将coclasses放在两个单独的库中时,代码会生成"无效类类型转换",删除[weak]属性时错误消失.请原谅奇数样本,其目的只是为了使问题最小化,不应该作为标准编码实践
这是第一个库.ridl文件,它定义了接口和容器的CoClass:
[
uuid(E1EE3651-A400-49BF-B5C5-006D9943B9C0),
version(1.0)
]
library DelphiIntfComLib
{
importlib("stdole2.tlb");
interface IMyContainer;
interface IMyContent;
coclass MyContainer;
[
uuid(A7EF86F7-40CD-41EE-9DA1-4D9B7B24F06B),
helpstring("Dispatch interface for MyContainer Object"),
dual,
oleautomation
]
interface IMyContainer: IDispatch
{
[id(0x000000C9)]
HRESULT _stdcall Add([in] IMyContent* AMyContent);
};
[
uuid(BFD6D976-8CEF-4264-B95A-B5DA7817F6B3),
helpstring("Dispatch interface for MyContent Object"),
dual,
oleautomation
]
interface IMyContent: IDispatch
{
[id(0x000000C9)]
HRESULT _stdcall SetWeakReferenceToContainer([in] IMyContainer* AContainer);
};
[
uuid(1F56198B-B1BE-4E11-BC78-0E6FF8E55214)
]
coclass MyContainer
{
[default] interface IMyContainer;
};
};
Run Code Online (Sandbox Code Playgroud)
这是我的容器实现
unit Unit1; …Run Code Online (Sandbox Code Playgroud) 我有一个适用于Delphi和Lazarus的单元.在Lazarus中,该单元编译时没有任何异常,但在Delphi中它给出了错误数据类型太大:超过2 GB.以下是代码:
unit UType;
{$ifdef FPC}
{$MODE delphi}{$H+}
{$endif}
interface
type
TFreqType = Extended;
TFreqCutArray = Array [0..0]of TFreqType;
PFreqCutArray = ^TFreqCutArray;
FilterOrder = Integer;
TAS_Sample = Extended;
TAS_SampleArray = Array[0..High(Integer) div Sizeof(TAS_Sample) - 1] of TAS_Sample;
PTAS_SampleArray = ^TAS_SampleArray;
TAS_Float = Extended;
TComplex = record
Re, Im: TAS_Sample; // Z = Re + i*Im
end;
PComplex = ^TComplex;
TComplexArray = Array[0..High(Integer) div Sizeof(TComplex) - 1] of TComplex;//here Delphi gives the error
PComplexArray = ^TComplexArray;
FilterProc = function(V: TAS_Sample): TAS_Sample …Run Code Online (Sandbox Code Playgroud)