DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: jsuguo
今日帖子: 29
在线用户: 10
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
男 zhyhero (zhyhero) ★☆☆☆☆ -
盒子活跃会员
2022/9/24 15:26:33
标题:
关于H2219提示,是否有可能单独针对某个定义关闭? 浏览:801
加入我的收藏
楼主: H2219 Private symbol '%s' declared but never used (Delphi)

例如
 private
   x:boolean;  //是否存在某种方法关闭针对定义x的H2219提示
   y:boolean;
----------------------------------------------
z@S7
作者:
男 1111111113 (1111111113) ▲△△△△ -
普通会员
2022/9/24 21:09:32
1楼: 如果只有2个bo 
建议用一个整数 或者 byte 代替
代码用
     case 来区别  xy同时存在 不同时存在的情况
8bit  每次取4bit  也就只要写15种不同的开关代码执行
----------------------------------------------
-
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/9/24 22:27:38
2楼: easy way to avoid "Hints" message is:


type
{$HINTS OFF}
  TMyClass = class
  private
    FBoo: boolean;
  public
  end;
{$HINTS ON}


...
var
  Form1: TForm1;

implementation

{$R *.dfm}
//
// NOTE: before and after procedure/function!  NOT on "block of code" into procedure/function!!!
//
// ---> Hints it's NOT an "error"!!! it just ask you to review your code to do better!!!
//
{ ...$WARNINGS OFF } // to avoid show "WARNINGS"

{$HINTS OFF } // to avoid show "HINTS"
procedure TForm1.Button1Click(Sender: TObject);
var
  MyVarEmptyAndDontUsed: boolean;
begin

end;
{$HINTS ON }
{ ...$WARNINGS ON }

procedure TForm1.FormCreate(Sender: TObject);
var
  MyNewVarDontUsed: boolean;
begin
  Caption := Self.Name;
end;

end.

----------
the good sense said:
--- if not necessary, then why have it?

----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 zhyhero (zhyhero) ★☆☆☆☆ -
盒子活跃会员
2022/9/24 23:24:34
3楼: @emailx45 thanks


  TMyType1 = record
  private
    Data: string;
    {$HINTS OFF}
    fish: boolean;
    small: boolean;
    river: boolean;
    {$HINTS On}
  public

  end;

  TMyType2 = record
  private
    Data: string;
    {$HINTS OFF}
    cat: boolean;
    white: boolean;
    {$HINTS On}
  public

  end;




  fld: TRttiField;
  isfish := fld.FieldType.GetField('fish') <> nil;
  issmall := fld.FieldType.GetField('small') <> nil;
  isriver := fld.FieldType.GetField('river') <> nil;
  iscat := fld.FieldType.GetField('cat') <> nil;
  iswhite := fld.FieldType.GetField('white') <> nil;



瞎想出来的一个用法,只有定义,用RTTI测试是否存在某个定义,所以编译器和IDE的H2219就成了扰乱信息了。
----------------------------------------------
z@S7
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/9/25 8:25:42
4楼: any way, a "Field"/var with "unknow value / without value" is always dangerous in critical/specific situations!

that way, it's good dont have it defined or use any other way to define it or not! ==  if "X-situation" then "define A", else, "define B"
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
作者:
男 zhyhero (zhyhero) ★☆☆☆☆ -
盒子活跃会员
2022/9/25 8:52:00
5楼: 我尝试把这种方法用在,针对Record类型的检测或推断(examine or infer)中,
尤其是只知道类型,而没有具体实例的时候。
----------------------------------------------
z@S7
作者:
男 emailx45 (emailx45) ▲▲▲▲△ -
普通会员
2022/9/25 10:15:44
6楼: well, then you can try use this:

Record with variant-parts!

type
  TMyEnums = (meOne, meTwo, etc...);

  TRec = record
    ... fields regular
  case FieldXX : TMyEnums of
    meOne: ( fieldA:double ); // "field : type managed" see help to "records"
    meTwo : ( fieldB: double);
  end;

Note: the "variant-parts" can use distinct type, but you need know like use it on client-code
---------
  case FieldXX : TMyEnums of
    meOne: ( fieldA:double ); // "field : type managed" see help to "records"
    meTwo : ( fieldB: integer ); // OK = double and integer can works in general!
---------

FieldA and FieldB using same address on memory to assign its value, then, in fact, you'll have just "ONE" field.

ex.
var
  MyRec : TRec;
begin
  MyRec.FieldXX := meOne;
  MyRec.FieldA := 10.0;
  //
  MyRec.FieldXX := meTwo;
  MyRec.FieldB := 14.00;

  MyRec.FieldA value = MyRec.FieldB value because, in fact, it's the same memory position to store the values (10.0 and 14.00), and the end, just "14.0" value will stay stored!

  MyRec.FieldA = 14.0 / MyRec.FieldB = 14.00

  "1" memory, to 2 possibilities on the context of programmer, just!


no hints :)
----------------------------------------------
The higher the degree, the greater the respect given to the humblest!RAD 11.3
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行70.3125毫秒 RSS