当我编译这段代码
{$WARNINGS ON}
function Test(s: string): string;
var
t: string;
d: double;
begin
if s = '' then begin
t := 'abc';
d := 1;
end;
Result := t + FloatToStr(d);
end;
Run Code Online (Sandbox Code Playgroud)
我收到警告"变量'd'可能尚未初始化",但我没有得到变量't'的相同警告.这似乎不一致.这段代码只是一个显示编译器警告的简单示例,但我刚刚在我的实时代码中发现了一个错误,该错误会被未初始化的字符串变量的编译时警告捕获.我可以在Delphi 6中以某种方式切换此警告吗?或者在较新版本的Delphi中?
我在打开 Delphi (D6 Pro) 后第一次构建/编译特定项目时收到此错误。后续构建不会给出错误。
对于磁盘上的文件,Win32函数FlushFileBuffers是否可靠,确定使用CloseHandle关闭文件然后使用CreateFile重新打开文件?
是否存在CloseHandle然后CreateFile更好的情况,因为当FlushFileBuffers没有时,它们正确地将数据保存到磁盘?
以下代码不会在D6中生成编译器警告.当我告诉ps指向一个字符串时,我可以告诉我将ps指向一个整数吗?
procedure Test;
var
i: integer;
s, m: string;
ps: ^string;
begin
s := 'Test message';
ps := @s;
m := ps^;
MessageDlg(m, mtInformation, [mbOK], 0); // This displays 'Test message'.
ps := @i; // I would like a warning here.
m := ps^;
MessageDlg(m, mtInformation, [mbOK], 0); // This might display garbage.
end;
Run Code Online (Sandbox Code Playgroud) 我想在Windows上生成随机加密密钥.我在哪里可以获得熵?
我希望我的熵函数在没有网络连接的情况下工作,并且在Windows 2000及更高版本上可靠.即使是可能提供或不提供少量熵的来源也可能是有用的,因为所有来源都将汇集在一起.
这是我最初的功能列表:
GetCurrentProcessID, GetCurrentThreadID, GetTickCount, GetLocalTime, QueryPerformanceCounter, GlobalMemoryStatus, GetDiskFreeSpace, GetComputerName, GetUserName, GetCursorPos, GetMessageTime, GetSystemInfo, CryptGenRandom, GetProcessHandleCount, GetProcessMemoryInfo.
我希望有两个程序可以相互调用,或者从运行的任何线程调用,但一次只运行一个.我怎样才能做到这一点?这会正常吗?
var
cs: TCriticalSection;
procedure a;
begin
cs.Acquire;
try
// Execute single threaded here.
finally
cs.Release;
end;
end;
procedure b;
begin
cs.Acquire;
try
// Execute single threaded here. Maybe with calls to procedure a.
finally
cs.Release;
end;
end;
Run Code Online (Sandbox Code Playgroud) 什么是悬垂树?
我是 Git 的新手,我正在使用适用于 Windows 的最新 Git-GUI。当我执行 Git-GUI Repository 时会报告悬空树:创建新存储库后验证数据库:

这是我新创建的空存储库:

它说“成功”,但是当我搜索“悬垂树”时,似乎有问题报告,而当我搜索“什么是悬垂树”时,我没有得到任何结果。我想知道一般什么是悬垂树,在这个特定实例中它是什么,这是否是一个问题。
我收到一个编译错误'Ambiguous overloaded call to ...'没有明显的原因.这似乎是Delphi 6中的一个错误.这个bug的范围是什么?它只影响'数组'参数的函数吗?它是否已在较新版本的Delphi中修复?
// This is a simple example to produce the compiler error, not a real program.
function ShowInt(const a: array of string; const i: longint): string; overload;
begin
Result := 'Longint ' + IntToStr(i);
end;
function ShowInt(const a: array of string; const i: int64): string; overload;
begin
Result := 'Int64 ' + IntToStr(i);
end;
procedure Test;
var
i64: int64;
ilong: longint;
begin
ShowInt([], i64 ); // In D6 why does this line compile …Run Code Online (Sandbox Code Playgroud)