你可以試試在下面程序段設置一下斷點,看看cdsCabMain.FieldByName('CMNo').Value的值
是怎樣變化的,再找解決方法:
procedure TForm1.PageControl1Change(Sender: TObject);
begin
if PageControl1.ActivePageIndex=1 then
begin
With DataMdo
begin
cdsCabPart.Close;
cdsCabPart.CommandText:='Select * from CabPart Where
CMNo='+IntToStr(cdsCabMain.FieldByName('CMNo').Value);
cdsCabPart.Open;
end;
end;
end;
通常我會用cdsCabMain.FieldByName('CMNo').AsString,而不用
IntToStr(cdsCabMain.FieldByName('CMNo').Value)。如果再有問題,試試以下笨方法:
procedure TForm1.PageControl1Change(Sender: TObject);
begin
if PageControl1.ActivePageIndex=1 then
begin
With DataMdo
begin
cdsCabPart.Active:=False;
//這里只是我喜愛用Active屬性多一點
if cdsCabMain.RecordCount>0 then
begin
if cdsCabMain.RecordCount=1 then
cdsCabMain.First;
cdsCabPart.CommandText:='Select * from CabPart Where
CMNo='+cdsCabMain.FieldByName('CMNo').AsString;
cdsCabPart.Active:=True;
end;
end;
end;
end;