我正在使用此代码为线程中的托盘图标设置动画(icon1和icon2在.res文件中):
while AnimationPending do
begin
TrayIcon.Icon.Handle := LoadIcon(hInstance,'icon1');
Sleep(300);
TrayIcon.Icon.Handle := LoadIcon(hInstance,'icon2');
Sleep(300);
end;
Run Code Online (Sandbox Code Playgroud)
我担心如果我在循环中执行它可能会造成内存泄漏,因为icon1/2会再次加载.
代码是否会造成内存泄漏,或者在循环中使用是否安全?
我正在尝试与需要摘要式身份验证的LAN(http://)服务器进行通信.
uses IdHttp, IdAuthenticationDigest;
...
begin
IdHttp1 := TIdHttp.Create(nil);
try
IdHttp1.Request.Username := 'xxx';
IdHttp1.Request.Password := 'xxx';
Result := IdHttp1.Get(URL)
finally
idHttp1.Free;
end;
end;
Run Code Online (Sandbox Code Playgroud)
不幸的是,我从服务器获得了HTTP/1.0 401 Unauthorized as IdHttp1.ResponseText.如果输入用户名和密码,Firefox和Chrome都可以正常连接.
我是SVN和Delphi 7的最新Indy 10.
服务器的http标头(LAN上为192.168.1.10):
Connecting...
Resolving hostname dm7020hd.
Connecting to 192.168.1.10.
Connected.
Server: webserver/1.0
Date: Thu, 31 Jan 2013 11:28:32 GMT
WWW-Authenticate: Digest algorithm="MD5", realm="Forbidden", qop="auth", opaque="7edfc2c756ad1f795651f15f88c32b25", nonce="d2ef913b753b3b6ad8878b34b93cfc5a"
Content-Type: text/html
Cache-Control: no-store, no-cache, must-revalidate
Expires: Sat, 10 Jan 2000 05:00:00 GMT
Content-Length: 15
Last-Modified: Thu, 31 Jan 2013 11:28:32 GMT
ETag: …Run Code Online (Sandbox Code Playgroud) 我在使用Delphi和Indy 9/10从特定Web服务器接收favicon.ico时遇到问题.其他服务器工作正常.问题不在于此Web服务器,因为wget命令行实用程序正确获取文件.
这是wget的输出:
c:\a>wget http://perforce.eigenbase.org:8080/favicon.ico
SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc
syswgetrc = c:/progra~1/wget/etc/wgetrc
--2013-01-27 00:12:39-- http://perforce.eigenbase.org:8080/favicon.ico
Resolving perforce.eigenbase.org... 72.14.190.177
Connecting to perforce.eigenbase.org|72.14.190.177|:8080... connected.
HTTP request sent, awaiting response... 200 No headers, assuming HTTP/0.9
Length: unspecified
Saving to: `favicon.ico'
[ <=> ] 2.862 --.-K/s in 0s
2013-01-27 00:12:40 (143 MB/s) - `favicon.ico' saved [2862]
Run Code Online (Sandbox Code Playgroud)
这是我的Delphi Indy 9/10示例代码.它生成一个"Connection Closed Gracefully"异常,结果是一个空字符串.
procedure TForm1.Button1Click(Sender: TObject);
var s: string;
begin
s := '';
try
s := IdHTTP1.Get('http://perforce.eigenbase.org:8080/favicon.ico');
except
on E: Exception do
begin
{$IFDEF DEBUG}ShowMessage('get error:'+E.Message){$ENDIF};
end; …Run Code Online (Sandbox Code Playgroud) Windows 8任务管理器显示CPU的当前(非最大)频率(例如1.2 GHz).有没有办法通过Windows API获得此频率?最好使用Delphi或Visual C++.
我有一个包含空字符的字符串.
我试图用这段代码将它保存到一个文件:
myStringList.Text := myString;
myStringList.SaveToFile('c:\myfile');
Run Code Online (Sandbox Code Playgroud)
不幸的是,如果源字符串在开头有一个空字符,则myStringList.Text为空.
我以为只有C字符串被空字符终止,Delphi总是很好用.
如何将字符串的内容保存到文件?
我使用以下代码获得了一个窗口句柄:
var h: THandle;
...
h := FindWindow('MozillaWindowClass', NIL);
Run Code Online (Sandbox Code Playgroud)
h有效(> 0).
如何确定此窗口是否有任何子窗口?
我不能使用FindWindowEx(),因为它需要一个类名.
我想在这里完成的是找出MozillaWindowClass窗口是属于Thunderbird还是Firefox.看起来Thunderbird有一个没有孩子的MozillaWindowClass,但Firefox没有,所以这将是一个快速找到的方法.(我不能使用CreateToolhelp32Snapshot()来查看进程名称,因为我的代码也需要在Windows 2000上运行).