There is a dataset "ibdsArchive",
Before opening a form in ibdsArchive, I create a dynamic field
var LField1: TStringField; if FMain.ibdsArchive.FindField('NAME_PAIRS') = nil then begin //add field 'NAME_PAIRS' FMain.ibdsArchive.Close; LField1 := TStringField.Create(FMain.ibdsArchive); LField1.FieldName := 'NAME_PAIRS'; with FMain.ibdsArchive.FieldDefs.AddFieldDef do begin Name := 'NAME_PAIRS'; DataType := ftString; Size := 20; end; LField1.DataSet := FMain.ibdsArchive; end; the field is created after working, when closing the form I want to delete this field
var TC: TComponent; … TC := FMain.FindComponent('ibdsArchiveNAME_PAIRS'); if TC <> nil then begin FMain.ibdsArchive.Close; TC.Free; FMain.ibdsArchive.Open; end; but it was not there, for some reason I have “ TC = nil ”, although the field is there (it is displayed in DBGrid).
The following code confuses me:
procedure TFGeneric.Button1Click(Sender: TObject); var TC: TComponent; begin if FMain.ibdsArchive.FindField('NAME_PAIRS') = nil then showmessage('№1 NAME_PAIRS не существет') else showmessage('№2 NAME_PAIRS существет'); TC := FMain.FindComponent('ibdsArchiveNAME_PAIRS'); if TC <> nil then showmessage('№3 NAME_PAIRS существет') else showmessage('№4 NAME_PAIRS не существет'); TC := FMain.FindComponent('ibdsArchivePAIRS_ID'); if TC <> nil then showmessage('№5 PAIRS_ID существет') else showmessage('№6 PAIRS_ID не существет'); showmessage('count fields: '+IntToStr(FMain.ibdsArchive.FieldCount)); showmessage(FMain.ibdsArchive.FieldList.Text); end; - when the button is pressed, the message pops up: No. 2 , No. 4 , No. 5 (“PAIRS_ID” is a stationary field);
FieldList - also displays, in the message this field.
Question :
why the field does not find atTC: = FMain.FindComponent ('ibdsArchiveNAME_PAIRS');
And with FMain.ibdsArchive.FindField ('NAME_PAIRS') - it finds and also finds other stationary fields, like " ibdsArchivePAIRS_ID ".