我们知道Dcu文件的规范是一个秘密,它将在每个版本中更改.有没有可能的方法来探索Delphi IDE中的dcu文件中的符号?(而不是使用反编译库,如DCU32INT项目.)
众所周知,当我们调用类的构造函数时:
instance := TSomeClass.Create;
Run Code Online (Sandbox Code Playgroud)
Delphi编译器实际上做了以下事情:
它简单易懂.但我不太确定编译器如何处理第二步和第三步中的异常.
似乎没有明确的方法在D2010中使用RTTI构造函数方法创建实例.所以我在Spring Framework for Delphi中编写了一个简单的函数来重现创建过程.
class function TActivator.CreateInstance(instanceType: TRttiInstanceType;
constructorMethod: TRttiMethod; const arguments: array of TValue): TObject;
var
classType: TClass;
begin
TArgument.CheckNotNull(instanceType, 'instanceType');
TArgument.CheckNotNull(constructorMethod, 'constructorMethod');
classType := instanceType.MetaclassType;
Result := classType.NewInstance;
try
constructorMethod.Invoke(Result, arguments);
except
on Exception do
begin
if Result is TInterfacedObject then
begin
Dec(TInterfacedObjectHack(Result).FRefCount);
end;
Result.Free;
raise;
end;
end;
try
Result.AfterConstruction;
except
on Exception do
begin
Result.Free;
raise;
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
我觉得这可能不是100%正确.所以请告诉我方式.谢谢!
我想在编辑视图中插入一个区域,然后折叠该区域.
// fEditView: IOTAEditView;
var
writer: IOTAEditWriter;
begin
writer := fEditView.Buffer.CreateUndoableWriter;
//...
writer.Insert('{$REGION ''Documentation''}'#13#10'{$ENDREGION}');
writer := nil; // Flush the buffer
fEditView.Position.GotoLine(lineNo); // go to the line number of the region
fEditView.Paint;
end;
Run Code Online (Sandbox Code Playgroud)
此代码段将在代码编辑器中插入一个区域.但IDE需要一些操作才能在代码编辑器中生成这样的区域.
有没有办法强制IDE执行此操作然后我可以使用
(fEditView as IOTAElideActions).ElideNearestBlock;
Run Code Online (Sandbox Code Playgroud)
折叠吗?
众所周知,有两种常见的做法可以确保延迟初始化的线程安全性:
似乎VCL使用了第二种做法.有什么缘故吗?
class function TEncoding.GetUTF8: TEncoding;
var
LEncoding: TEncoding;
begin
if FUTF8Encoding = nil then
begin
LEncoding := TUTF8Encoding.Create;
if InterlockedCompareExchangePointer(Pointer(FUTF8Encoding), LEncoding, nil) <> nil then
LEncoding.Free;
end;
Result := FUTF8Encoding;
end;
Run Code Online (Sandbox Code Playgroud)
或者有更好的方法吗?
谢谢!