在样式为csOwnerDrawFixed的TComboBox后代组件上实现"在键入时查找"行为的正确方法是什么?
我有一个类层次结构,这个:
type
TMatrix = class
protected
//...
public
constructor Create(Rows, Cols: Byte);
//...
type
TMinMatrix = class(TMatrix)
private
procedure Allocate;
procedure DeAllocate;
public
constructor Create(Rows, Cols: Byte);
constructor CreateCopy(var that: TMinMatrix);
destructor Destroy;
end;
Run Code Online (Sandbox Code Playgroud)
如您所见,派生类和基类构造函数都具有相同的参数列表.我从派生的一个显式调用基类构造函数:
constructor TMinMatrix.Create(Rows, Cols: Byte);
begin
inherited;
//...
end;
Run Code Online (Sandbox Code Playgroud)
是否有必要在Delphi中显式调用基类构造函数?可能是我需要放置重载或覆盖以清除我打算做什么?我知道如何在C++中实现它 - 只有当你想要传递一些参数时才需要显式调用基类构造函数 - 但我在Delphi编程方面没有多少经验.
我在线程中使用XE/XE2中的SOAP时遇到问题.(我没有使用较旧的Delphis进行测试.)在主线程中工作的简单代码在使用时破坏THTTPReqResp实例时崩溃Invalid pointer operation.
这是完整的计划.表单只包含一个触发btnTestClick事件的按钮:
unit Unit79;
interface
uses
SysUtils, Forms, Classes, Controls, StdCtrls, ComObj,
ActiveX, InvokeRegistry, SOAPHTTPTrans, Rio, SOAPHTTPClient;
type
TForm79 = class(TForm)
btnTest: TButton;
procedure btnTestClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form79: TForm79;
implementation
{$R *.dfm}
procedure TForm79.btnTestClick(Sender: TObject);
begin
TThread.CreateAnonymousThread(
procedure
var
FHTTPReqResp: THTTPReqResp;
FHTTPRIO: THTTPRIO;
begin
if CoInitializeEx(NIL, COINIT_MULTITHREADED or COINIT_SPEED_OVER_MEMORY) = S_OK then try
FHTTPReqResp := THTTPReqResp.Create(nil);
with FHTTPReqResp do begin
Name := 'HTTPReqResp1';
UseUTF8InHeader := …Run Code Online (Sandbox Code Playgroud) 是否有可能挂钩到Windows上的线程终止?IOW,如果进程内的线程(对其他进程及其线程不感兴趣)已经终止(通常或者 - 更重要 - 强制),我希望得到通知.
或者,挂钩创建线程也可以.
基本原理:我有一个库,可以在每个线程的基础上管理一些信息(将其视为某些信息的进程范围的每线程缓存).线程终止时,我必须从缓存中删除所有特定于线程的信息.[缓存关联使用线程ID实现,可能会为将来的线程重用.]
"正常"执行顺序没有问题,因为库用户将从库中分离当前线程以清除状态.如果有人杀死拥有缓存资源的线程,问题就会开始出现.
我有这个原子乐观的初始化类:
type
Atomic<T: IInterface> = class
type TFactory = reference to function: T;
class function Initialize(var storage: T; factory: TFactory): T;
end;
class function Atomic<T>.Initialize(var storage: T; factory: TFactory): T;
var
tmpIntf: T;
begin
if not assigned(storage) then begin
tmpIntf := factory();
if InterlockedCompareExchangePointer(PPointer(@storage)^, PPointer(@tmpIntf)^, nil) = nil then
PPointer(@tmpIntf)^ := nil;
end;
Result := storage;
end;
Run Code Online (Sandbox Code Playgroud)
现在我想为对象实现相同的模式.
type
Atomic<T: class> = class
type TFactory = reference to function: T;
class function Initialize(var storage: T; factory: TFactory): T;
end;
class …Run Code Online (Sandbox Code Playgroud) 我将重新安装Windows,我想知道是否有办法备份/恢复Delphi许可证信息,所以我不会"失去"我的一个安装.
换句话说 - 有没有办法卸载Delphi,重新安装Windows,重新安装Delphi而不被视为"新"安装?
[我想彻底消灭我的电脑并从头开始.我将重新安装XE5,XE7和10 Seattle.]
我想加载一个 DLL(来自 VCL 应用程序,但这不重要[这不是真的,因为 VCL 和 FMX 都包含消息循环])并显示在该 DLL 中创建的 FireMonkey 模式窗体。显示表格工作正常,但我在清理之后遇到问题......
我只能找到 2011/2012 年关于该主题的文章,而且它们大多指的是 XE2。遗憾的是,这些解决方案不再起作用。(或者我做错了什么。)
所有示例文件都在这里:https : //github.com/gabr42/GpDelphiCode/tree/master/FMX%20from%20DLL
我的 DLL 只是导出ShowMainForm.
library FMXDLL;
uses
System.SysUtils,
System.Classes,
FMXMain in 'FMXMain.pas' {FormMain};
{$R *.res}
exports
ShowMainForm;
begin
end.
Run Code Online (Sandbox Code Playgroud)
ShowMainForm初始化 GDI+,然后显示窗体。之后,它尝试清理但失败了。
uses
Winapi.GDIPAPI,
Winapi.GDIPOBJ;
procedure InitGDIP;
begin
// Initialize StartupInput structure
StartupInput.DebugEventCallback := nil;
StartupInput.SuppressBackgroundThread := False;
StartupInput.SuppressExternalCodecs := False;
StartupInput.GdiplusVersion := 1;
GdiplusStartup(gdiplusToken, @StartupInput, nil);
end;
procedure FreeGDIP;
begin
if Assigned(GenericSansSerifFontFamily) then
GenericSansSerifFontFamily.Free;
if Assigned(GenericSerifFontFamily) …Run Code Online (Sandbox Code Playgroud) 我想用Delphi(2009 - 所以我有通用字典类)写一些类似于C#代码的东西:
Dictionary<Type, Object> d = new Dictionary<Type, Object>();
d.Add(typeof(ISomeInterface), new SomeImplementation());
object myObject = d[typeof(ISomeInterface)];
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
提前致谢,
斯托伊奇
看下面的代码,为什么Trunc函数的结果不同?
procedure TForm1.Button1Click(Sender: TObject);
var
D: Double;
E: Extended;
I: Int64;
begin
D := Frac(101 / 100) * 100;
E := Frac(101 / 100) * 100;
I := Trunc(D);
ShowMessage('Trunc(Double): ' + IntToStr(I)); // Trunc(Double): 1
I := Trunc(E);
ShowMessage('Trunc(Extended): ' + IntToStr(I)); // Trunc(Extended): 0
end;
Run Code Online (Sandbox Code Playgroud) 以下代码(仅用于演示问题)构建并在Delphi 2010中工作.在Delphi 2009中,编译器失败并显示"E2035实际参数不足".
program Project50;
{$APPTYPE CONSOLE}
uses
SysUtils;
type
TMyProc = reference to procedure(param: integer);
var
a: TProc;
b: TMyProc;
begin
b := procedure (param: integer)
begin
end;
a := TProc(b); // <-- [DCC Error] Project50.dpr(19): E2035 Not enough actual parameters
end.
Run Code Online (Sandbox Code Playgroud)
我发现只有一个非常难看的黑客来解决这个问题(a:TProc绝对b).有没有人知道这个编译器缺陷的更好的解决方法?
[TProc字段实际上隐藏在可以存储各种'可执行'代码的记录中 - TProcedure,TMethod和TProc.Casting用于将特定的匿名proc存储到此字段中.]
delphi ×9
delphi-2009 ×2
constructor ×1
delphi-xe ×1
dll ×1
firemonkey ×1
generics ×1
hook ×1
inheritance ×1
reinstall ×1
soap ×1
vcl ×1
windows ×1