system.object は次のとおりです。
TTrendGroup = class(System.Object)
SigList:ArrayList;
Rate,Phase,Delay:SmallInt;
RateIndex,PhaseIndex:SmallInt;
firstTime:Boolean;
base:integer;
Enabled:Boolean;
name:string;
public
constructor;
method AddTGroup(signal:TTrendSignal);
method Clear;
method Poll(list:ArrayList);
method ReadTGroup(bTGr:BinaryReader);
method WriteTGroup(bTGw:BinaryWriter);
method WriteSignals(bWSw:BinaryWriter);
method ToString:String;override;
end;
constructor TTrendGroup;
begin
SigList := new ArrayList;
Rate := 30;
Phase := 0;
Delay := Phase;
RateIndex := 4;
PhaseIndex := 0;
firsttime := true;
enabled := true;
name := '';
end;
上記の system.object からオブジェクトを作成し、それを GroupList ListBox に追加する方法は次のとおりです。
method HTrendFrm.AddGroup1_Click(sender: System.Object; e: System.EventArgs);
var
i:integer;
grp:TTrendGroup;
begin
if ReadWrite then
begin
grp := new TTrendGroup;
grp.name:='New Group';
i := GroupList.Items.Add(grp);
GroupList.SelectedIndex := i;
grpName.Text := 'New Group';
PollBtn.Checked := grp.Enabled;
RateBox.SelectedIndex := grp.RateIndex;
PhaseBox.SelectedIndex:= grp.PhaseIndex;
SignalListBox.Items.Clear;
UpdateButtons;
end;
end;
追加したばかりの system.object を取得する方法は次のとおりです。
method HTrendFrm.GroupList_Click(sender: System.Object; e: System.EventArgs);
var
grp:TTrendGroup;
begin
if (GroupList.SelectedIndex = -1) then exit;
with GroupList do
begin
grp := TTrendGroup(items[SelectedIndex]); <<<<< HERE is WHERE THE PROBLEM IS. grp always returns NIL.
end;
end;
どうしてか分かりません。このプログラムの他の部分に非常によく似たコードがあり、期待どおりに動作します。
私は何を間違っていますか?