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 at

    TC: = FMain.FindComponent ('ibdsArchiveNAME_PAIRS');

And with FMain.ibdsArchive.FindField ('NAME_PAIRS') - it finds and also finds other stationary fields, like " ibdsArchivePAIRS_ID ".

    1 answer 1

    The name of the field in the data and the name of the components on the form are different things.

     LField1 := TStringField.Create(FMain); // Owner - FMain LField1.Name := 'ibdsArchiveNAME_PAIRS'; ... TC := FMain.FindComponent('ibdsArchiveNAME_PAIRS'); // TC - not nil 
    • maybe I made a mistake somewhere, but I also don’t find it ... <br/> if FMain.ibdsArchive.FindField ('NAME_PAIRS') = nil then begin // add field 'NAME_PAIRS' FMain.ibdsArchive.Close; LField1: = TStringField.Create (FMain); LField1.FieldName: = 'NAME_PAIRS'; with FMain.ibdsArchive.FieldDefs.AddFieldDef do begin Name: = 'ibdsArchiveNAME_PAIRS'; DataType: = ftString; Size: = 20; end; LField1.DataSet: = FMain.ibdsArchive; end; - Konstantin78
    • @ Konstantin78 hmm, can you see the second line of code in my answer? - Igor
    • Yes, thanks, everything worked out, I confused her with the existing one - Name: = 'ibdsArchiveNAME_PAIRS'; - although these are two different things - Konstantin78