我已经为给定的类声明了私有字段和公共属性.
从其他单位我可以通过提供访问权限的公共财产访问该字段.
但是在声明此类的同一单元内,我可以选择直接或通过属性访问该字段.
建议的最佳实践是什么:直接读/写字段或通过提供读写访问权限的属性?
我想知道是否有一些delphi库用于检测文本文件的字符编码.
例如,如何在数据库中存储方法体,然后运行它?(我正在使用Delphi XE2;也许RTTI会有所帮助.)
我有两个双胞胎CentOS 5.4服务器,每个服务器都安装了VMware Server.
假设我总是将稀疏文件用于我的vmware虚拟机,那么将虚拟机文件从一台服务器复制到另一台服务器的最可靠,最快速的方法是什么?
vm的文件很难复制,因为它们非常大(50 GB),但由于它们是稀疏文件,我认为可以采取一些措施来提高复制的速度.
如果我在Firebird数据库中创建一个新表,然后我调用:
TIBDatabase.GetTableNames,新创建的表没有得到颂扬:我首先发出:
IBDatabase1.Connected := False;
IBDatabase1.Connected := True;
Run Code Online (Sandbox Code Playgroud)
然后我可以调用TIBDatabase.GetTableNames并枚举新创建的表.
以下函数使用TIBDatabase.GetTableNames来确定是否存在作为参数传递的给定表名
function TableExists(const aTableName: String): Boolean;
var
ListOfExistingTables: TStringList;
begin
Result:= False;
ListOfExistingTables:= TStringList.Create;
try
IBDatabase1.GetTableNames(ListOfExistingTables);
Result:= (ListOfExistingTables.IndexOf(aTableName) > - 1);
finally
ListOfExistingTables.Free;
end;
end;
Run Code Online (Sandbox Code Playgroud) 如果我在方法中调用Application.Terminate OR Application.MaiForm.Close.申请没有终止!
procedure doSomething;
var
ErrorFound: boolean;
begin
[...]
try
if ErrorFound then
Application.Terminate;
finally
[...]
end;
end;
Run Code Online (Sandbox Code Playgroud)
我不明白为什么.
请注意,我正在尝试部分的Try ... Finally块中调用Application.Terminate.
我无法想象如何使用UNIX行结尾(LF)而不是默认的CRLF来保存TStringList的行.
我试图在stringList.Text属性上使用StringReplace()而没有任何成功:-(
我需要从字符串中删除重复的空格.从互联网上抓取的以下代码可以正常工作,除了它复制了字符串的第一个字符串.也许这有更快的东西.
function DeleteRepeatedSpaces(OldText: string): string;
var
i: integer;
s: string;
begin
if length(OldText) > 0 then
s := OldText[1]
else
s := '';
for i := 1 to length(OldText) do
begin
if OldText[i] = ' ' then
begin
if not (OldText[i - 1] = ' ') then
s := s + ' ';
end
else
begin
s := s + OldText[i];
end;
end;
DelDoubleSpaces := s;
end;
Run Code Online (Sandbox Code Playgroud) 如何避免显示H2219提示?
H2219:声明但未使用的私有符号'%s'(Delphi)
我已经创建了一些导致这些提示的方法,因此提示是合法的.但我不使用任何这些方法.我想留下所有编译器消息,因为我认为这是一个很好的做法.
有提示吗?
前一段时间,我不记得在哪里,我读过有关delphi的最佳实践。
代替这个:
if FileExists(MyFile) then begin
if not DeleteFile(MyFile) then
ShowMessage('Unable to delete file');
end;
Run Code Online (Sandbox Code Playgroud)
写这个:
if not DeleteFile(MyFile) then
ShowMessage('Unable to delete file');
Run Code Online (Sandbox Code Playgroud)
他的优点和缺点是什么?
我如何释放泛型TList<T>?
我知道我可以在创建它时使用TObjectListwith 。AOwnsObjects = True
我很好奇,如何以通用方式重写以下方法,以便它可以在非托管引用(指针或类)T时释放?T
procedure FreeList(const List: TList);
var
i: Integer;
begin
if (List = nil) then
Exit;
for i := Pred(List.Count) downto 0 do
if Assigned(List[i]) then
TObject(List[i]).Free;
List.Clear;
end;
Run Code Online (Sandbox Code Playgroud) 虽然以下代码使用鼠标所在单元格的文本正确设置Form1.Caption,但它不会显示任何DBGrid.Hint,除非我单击该单元格.
这张照片出了什么问题?
type
THackGrid = class(TDBGrid); // to expose protected DataLink property
procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
Cell: TGridCoord;
ActRec: Integer;
begin
Cell := DBGrid1.MouseCoord(X, Y);
if dgIndicator in DBGrid1.Options then
Dec(Cell.X);
if dgTitles in DBGrid1.Options then
Dec(Cell.Y);
if THackGrid(DBGrid1).DataLink.Active and (Cell.X >= 0) and
(Cell.Y >= 0) then
begin
ActRec := THackGrid(DBGrid1).DataLink.ActiveRecord;
try
THackGrid(DBGrid1).DataLink.ActiveRecord := Cell.Y;
Caption := DBGrid1.Columns[Cell.X].Field.AsString; // Form1.Caption shows fine!
DBGrid.Hint := DBGrid1.Columns[Cell.X].Field.AsString; // <== Hint only shows when I …Run Code Online (Sandbox Code Playgroud) 我怎样才能防止这个警告?[DCC 警告] uFvSystem.pas(293): W1024 组合有符号和无符号类型 - 加宽了两个操作数
function LinkerTimestamp: TDateTime; overload;
begin
Result := PImageNtHeaders(HInstance + PImageDosHeader(HInstance)^._lfanew)
^.FileHeader.TimeDateStamp / SecsPerDay + UnixDateDelta;
end;
Run Code Online (Sandbox Code Playgroud)