如果我有一个TidTCPServer
实例,我宣布一个TFormatSettings
并在Create
常规填充它,是安全的,这种变量(例如调用线程的Execute
方法Format ('%1.6f', [SomeReal], AFormatSettings])
,当可能有不止一个上下文中执行?德尔福2007年,印 - 是一个变量声明在TidTCPServer线程安全的上下文?
如果没有,我怎么可能使线程安全的引用?
如果我有一个TidTCPServer
实例,我宣布一个TFormatSettings
并在Create
常规填充它,是安全的,这种变量(例如调用线程的Execute
方法Format ('%1.6f', [SomeReal], AFormatSettings])
,当可能有不止一个上下文中执行?德尔福2007年,印 - 是一个变量声明在TidTCPServer线程安全的上下文?
如果没有,我怎么可能使线程安全的引用?
它是线程安全的,只要你正在修改AFormatSettings
只有当没有任何线程访问它(如在激活服务器之前初始化它),以及线程只能从中读取。Format()
不会修改传递给它的TFormatSettings
。
如果您对线程安全性有疑问,可以创建以下函数并使用它来代替格式。
ThdSafeFormat(const aFormat: string; const aArgs: array of const): string;
var
FormatSettings: TFormatSettings;
begin
GetLocaleFormatSettings(LOCALE_USER_DEFAULT, FormatSettings);
Result := Format(aFormat, aArgs, FormatSettings);
end;
完美。感谢雷米。 – rossmcm