2

我在表单上有组件并寻找任何TMachine类型然后一旦我找到一个我想从组件中获取一些信息。我的问题是:我声明mTMachine 然后尝试分配m := Components[i] 但不会让我因为m是 TMachine 类型和组件是组件类型。有关如何解决此问题的任何帮助,以便我可以将找到的组件用作 TMachine?

procedure TfDeptLayout.bSaveClick(Sender: TObject);
var
  i: Integer;
  m : TMachine;
  Number,Zone,Dept,Name,Asset,IsPanel,BasicName,FinalLocation,Left,Top : String;
begin
bSave.Visible := false;
for i := ComponentCount -1 downto 0 do
  begin
    if(Components[I] is TMachine) then
      begin
        M := Components[I];
        Number := m.mnNumber;
        Name := m.mnName;
        Asset := m.mnAsset;
        IsPanel := m.mnIsPanel;
        BasicName := m.mnBasicName;
        if checkbox1.Checked then
          FinalLocation := 'shop'
        else
          FinalLocation := 'w';
        Left := inttostr(m.Left);
        top := inttostr(m.Top);
        Zone := myZone;
        Dept := myDept;
        Showmessage('Zone: '+Zone+' Dept: '+Dept
            +'Name : '+Name+' Number: '+Number+' Asset: '+Asset
            +'IsPanel: '+Ispanel+' BasicName: '+BasicName+
            ' FinalLocation : '+FinalLocation+' Left: '+Left+
            +' Top: '+Top);
      end;
  end;
4

1 回答 1

4

您需要使用类型转换来解决类型不匹配问题:

if(Components[I] is TMachine) then
  begin
    M := TMachine(Components[I]);
于 2013-03-04T07:12:47.400 回答