【问题标题】:Custom Dialog Box自定义对话框
【发布时间】:2012-07-20 18:58:04
【问题描述】:

试图让自定义对话框与按钮名称武器 1 、武器 2 和取消一起工作。但是使用此代码,当我尝试编译它时,它会在 Result 上给出错误未定义 错误信息是

[DCC 错误] ssClientHost.pas(760): E2003 Undeclared identifier: 'Result'

代码是:

      with CreateMessageDialog('Pick What Weapon', mtConfirmation,mbYesNoCancel) do
       try
           TButton(FindComponent('Yes')).Caption := Weapon1;
           TButton(FindComponent('No')).Caption := Weapon2;
           Position := poScreenCenter;
           Result := ShowModal;
        finally
     Free;
   end;
     if buttonSelected = mrYes    then ShowMessage('Weapon 1 pressed');
     if buttonSelected = mrAll    then ShowMessage('Weapon 2 pressed');
     if buttonSelected = mrCancel then ShowMessage('Cancel pressed');

【问题讨论】:

  • 是“结果”未定义还是“显示模式”未定义?
  • [DCC 错误] ssClientHost.pas(760): E2003 Undeclared identifier: 'Result'
  • 那么你不在一个函数中。结果是函数的结果,在过程中没有意义,所以不可用。

标签: delphi


【解决方案1】:

上面发布的代码有很多错误,除非有些部分您没有向我们展示。一方面,如果没有字符串变量Weapon1Weapon2,那么你不能引用这些变量!其次,如果没有Result 变量(例如,如果代码在函数内部),那么这也是一个错误。此外,在您上面的代码中,buttonSelected 是一个变量,您也可能忘记声明它。最后,先说说YesNo,再谈YesYes to all

以下代码有效(独立):

with CreateMessageDialog('Please pick a weapon:', mtConfirmation, mbYesNoCancel) do
  try
    TButton(FindComponent('Yes')).Caption := 'Weapon1';
    TButton(FindComponent('No')).Caption := 'Weapon2';
    case ShowModal of
      mrYes: ShowMessage('Weapon 1 selected.');
      mrNo: ShowMessage('Weapon 2 selected.');
      mrCancel: ShowMessage('Cancel pressed.')
    end;
finally
  Free;
end;

免责声明:此答案的作者不喜欢武器。

【讨论】:

  • 我喜欢免责声明 ;-)。
  • 啊,明白了,感谢帮助武器在别处定义,使用案例而不是结果效果很好! ..也是游戏的武器;D
【解决方案2】:

结果只定义在一个函数中:

function TMyObject.DoSomething: Boolean;
begin
  Result := True;
end;

procedure TMyObject.DoSomethingWrong;
begin
  Result := True;    // Error!
end;

所以,你会得到类似的东西:

function TMyForm.PickYourWeapon(const Weapon1, Weapon2: string): TModalResult;
begin
  with CreateMessageDialog('Pick What Weapon', mtConfirmation,mbYesNoCancel) do
    try
      TButton(FindComponent('Yes')).Caption := Weapon1;
      TButton(FindComponent('No')).Caption := Weapon2;
      Position := poScreenCenter;
      Result := ShowModal;
   finally
     Free;
   end;
   // Debug code?
{$IFDEF DEBUG)
   if Result = mrYes then 
     ShowMessage('Weapon 1 pressed');
   if Result = mrAll then 
     ShowMessage('Weapon 2 pressed');
   if Result = mrCancel then 
     ShowMessage('Cancel pressed');
{$ENDIF}
end;

【讨论】:

  • 现在我想起来了,我知道 :D ... 但是此代码是作为使用 CreateMessageDialog 的示例发布的。我对这里的一些事情感到困惑。
猜你喜欢
  • 2018-08-30
  • 2012-08-13
  • 2013-01-06
  • 2012-08-27
  • 2011-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多