gpt4 book ai didi

delphi - Fxxx私有(private)类名前缀约定从何而来?

转载 作者:行者123 更新时间:2023-12-03 14:42:48 24 4
gpt4 key购买 nike

在 C++/C# 中,私有(private)类变量的常见约定是 m_MyPrivateVar,我相信“m_”代表“my”(我可能是错的)。

在 Delphi 中,私有(private)类变量以 F 开头,例如FHandle等

F是什么意思?福? :)

最佳答案

有一些命名约定,以免在代码中迷失。

这里有一个例子来说明为什么这很有用。

// Types begins with T
TFoo = class
strict private
// sometimes I saw strict private fields beginning with underscore
// I like this too
_Value : string;
private
// private class vars are Fields and therefore begins with F
FValue : string;
function GetValue : string;
public
property Value : string read GetValue write FValue;

// Parameters should NOT begin with P (P is for Pointer) but with A
// because "i will pass A value" :o)
function GetSomething( const AValue : string ) : string;
end;

function TFoo.GetValue : string;
begin
Result := '*' + FValue + '*';
end;

function TFoo.GetSomething( const AValue : string ) : string;
var
// IMHO there is no naming convention to Local vars
// but mine begins with L
LValue : string;
begin

LValue { local var } :=
Value { property via getter } +
AValue { parameter } +
FValue { field };

Result := LValue;
end;

关于delphi - Fxxx私有(private)类名前缀约定从何而来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14268441/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com