我想完全禁用/删除该警告,因为我的包是一个完整的 RAD 服务器模块,因此这些线程变量将永远没有机会在包外部使用。
我已经在 threadvar 定义上尝试了 {$WARNINGS OFF},但它并没有删除警告。
unit CustomSession;
interface
uses
System.Classes,
System.SysUtils,
EMS.ResourceAPI;
type
TKpSession = record
UserId: string;
UserName: string;
SessionToken: string;
class procedure ValidateRequest(const AContext: TEndpointContext); static;
end;
{$WARNINGS OFF}
threadvar
KpSession: TKpSession;
{$WARNINGS ON}
resourcestring
rsNotLoggedIn = 'You need to be logged in to access %s - %s';
implementation
uses
CustomLocalize;
class procedure TKpSession.ValidateRequest(const AContext: TEndpointContext);
var
UserId, Resource, Endpoint: string;
begin
Resource := AContext.Request.Resource;
Endpoint := AContext.EndpointName;
if Assigned(AContext.User) then
UserId := AContext.User.UserName;
if UserId.Trim <> '' then
begin
KpSession.UserId := UserId;
KpSession.UserName := UserId; // Retrieve username from the DDBB ?
KpSession.SessionToken := AContext.User.SessionToken;
// to-do: Check Permissions for the User on this Request/Endpoint.
end
else
begin
raise Exception.CreateFmt(_(rsNotLoggedIn), [Resource, Endpoint]);
end;
end;
end.
您可以将此行放在该单元顶部的某个位置: