我需要检测TAdoConnection组件何时丢失与服务器的连接.我尝试过使用OnDisconnect事件,但这仅在调用Close方法或Connected属性设置为false时触发.
我尝试过的另一个选择是使用TTimer并执行这样的查询
SELECT 1 RESULT FROM DUAL
Run Code Online (Sandbox Code Playgroud)
在OnTimer事件中,捕获发生的任何异常.
有没有更好的选择来检测连接丢失?
我需要激活ReportMemoryLeaksOnShutdown功能来报告我的应用程序的内存泄漏,但只能在调试模式下(当Delphi IDE运行时).我怎样才能做到这一点?
启用VCL样式时,我需要更改TPanel的颜色.我尝试使用和修改"启用VCL样式更改编辑控件的颜色 "一文中列出的代码,但它不适用于TPanel.如何在启用VCL样式的情况下更改TPanel的颜色?
我需要在运行时添加一个png图像到TImageList.我已经看过了它实现的功能,TCustomImageList但它们只允许添加
例如:
function Add(Image, Mask: TBitmap): Integer;
function AddIcon(Image: TIcon): Integer;
function AddImage(Value: TCustomImageList; Index: Integer): Integer;
procedure AddImages(Value: TCustomImageList);
function AddMasked(Image: TBitmap; MaskColor: TColor): Integer;
Run Code Online (Sandbox Code Playgroud)
如何在不将此图像转换为BMP的情况下将PNG图像添加到ImageList组件?
IDE已经可以在设计时将PNG添加到ImageList:
现在我们需要在运行时完成它.
我写了一个Thread.descendent类,并在execute方法中我放了一个无限循环来监听一个com事件,被认为是一个糟糕的线程练习使用无限循环来做到这一点?应用程序工作正常,不冻结,总是响应,我只是回答因为我想使用最好的方法来线程化.
procedure TMyThread.Execute;
begin
while True and not Terminated do
begin
AResult:= FListener.GetResult(Param1,Param2,5000);
if not VarIsNull(AResult) then
Synchronize(Process);
end;
end;
Run Code Online (Sandbox Code Playgroud) 我需要在Delphi中开发一个实时(即,每秒至少请求和接收一次信息)监视应用程序,它监视多个远程设备(可能是数百个).通过TCP/IP进行通信.
我正在寻找建议开发这个应用程序,避免100%的CPU消耗,并尽量减少使用的RAM量.换句话说,我希望我的应用程序保持响应,而不是阻止系统或消耗所有资源.
我主要担心的是使用线程来监控每个远程设备.我的应用程序可以创建的线程数是否有限制?可以使用低优先级或中优先级启动线程以最小化CPU消耗吗?
关于最佳内存使用的建议也是受欢迎的.
我正在使用该WaitForMultipleObjects函数等待几个线程的最终确定,但我做错了,因为结果不是预期的
请参阅此示例代码
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
end;
TFoo = class(TThread)
private
Factor: Double;
procedure ShowData;
protected
procedure Execute; override;
constructor Create(AFactor : Double);
end;
var
Form1: TForm1;
implementation
Uses
Math;
{$R *.dfm}
{ TFoo }
constructor TFoo.Create(AFactor: Double);
begin
inherited Create(False);
Factor := AFactor;
FreeOnTerminate := True;
end;
procedure TFoo.Execute;
const
Max=100000000;
var
i : Integer;
begin
inherited;
for i:=1 to Max do
Factor:=Sqrt(Factor);
Synchronize(ShowData);
end;
procedure TFoo.ShowData;
begin
Form1.Memo1.Lines.Add(FloatToStr(Factor)); …Run Code Online (Sandbox Code Playgroud) 我正在测试Delphi XE2并且我创建了一个新的FireMonkey HD应用程序,但我有一个问题,FireMonkey表单的表单设计器不可见或可用,视图菜单中的选项切换表单/单元也被禁用以及工具栏按钮在表单和代码之间切换,即使使用F12也不起作用.我尝试了Shitf-F12选项(窗体窗口),但没有列出任何形式.我也尝试添加新的firemonkey表单,但是没有显示任何表单,只有代码可见. - 解决这个问题的任何建议?
我使用的是一个非常大的delphi第三方库,没有源代码,这个库有几个带抽象方法的类.我需要确定运行时Descendant类实现abtract方法的时间,以避免EAbstractError: Abstract Error向用户显示自定义消息或使用其他类代替.
例如,在此代码中,我想在运行时检查是否MyAbstractMethod已实现.
type
TMyBaseClass = class
public
procedure MyAbstractMethod; virtual; abstract;
end;
TDescendantBase = class(TMyBaseClass)
public
end;
TChild = class(TDescendantBase)
public
procedure MyAbstractMethod; override;
end;
TChild2 = class(TDescendantBase)
end;
Run Code Online (Sandbox Code Playgroud)
我如何确定在运行时的Descendant类中是否实现了抽象方法?
我有一个控制台应用程序,当输出重定向(外部)到文件或管道时,必须禁用或启用某些操作(myapp.exe> Foo.bar)
如何检查我的Delphi控制台应用程序是否重定向到文件或管道?
delphi ×10
delphi-xe ×5
delphi-xe2 ×2
ado ×1
firemonkey ×1
ide ×1
redirect ×1
vcl-styles ×1
winapi ×1
windows ×1