Stano 143 Posted October 4, 2022 (edited) Hi, Subform for "List". The structure is always: PrimaryKey Title The problem is that if I don't create the fields, the names are ''. This is a problem for the function function TjstIBCNavigator.LocateRecord(const PKeyValue: Integer; const FieldIdx: Integer = 0): Boolean; begin if FieldIdx > 0 then FPKeyName := FDataSource.DataSet.Fields.Fields[FieldIdx].FieldName; // Here I get '' Result := FDataSource.DataSet.Locate(FPKeyName, PKeyValue, [loCaseInsensitive]); // Failure of course end; If I create them, I get them when I open the table Quote 'ibtblCollection: Type mismatch for field 'IDDIVISIONS', expecting: Unknown actual: Integer Field.Data Type cannot be set because it is Read Only. How can it be solved? I might throw a chart in there just in case. This is not clean and especially not universal! Edited October 4, 2022 by Stano Share this post Link to post
Stano 143 Posted October 5, 2022 Such a solution came to his mind at design time, use one table and generate fields in it at runtime set properties that change They are mainly Name of the table Name of the first field - primary key That should work in my opinion. Share this post Link to post
Uwe Raabe 2057 Posted October 5, 2022 I'm sorry, but I cannot understand your problem in the first place. Can you create a small example to allow us to reproduce? Share this post Link to post
Stano 143 Posted October 5, 2022 3 hours ago, Uwe Raabe said: I'm sorry, but I cannot understand your problem in the first place. Can you create a small example to allow us to reproduce? I don't know how to do that example. Leave it at that. At least I'll describe what I'm trying to do. I have tables with a structure Primary key Title I am trying to create a single subform that would apply to all tables. I have (one each) TIBCDataSource and TIBCTable on it. I would like to modify the TIBCTable on run time as needed. My attempt: procedure TCollection.SetTable; begin FTable.TableName := FDataCollection.TableName; var FldName := 'ID' + FDataCollection.TableName; FTable.IndexFieldNames := FldName; FTable.Fields.Fields[0].FieldName := FldName; FTable.Fields.Fields[0].Name := 'intgrfldCollection' + FldName; FTable.Fields.Fields[0].DisplayLabel := FldName; FTable.Fields.Fields[1].Size := FDataCollection.TitleLength; end; I can not do that. I set the parameters before opening the table I will programmatically open the table. I have no idea when it will actually open On Locate, the original name is loaded in FDataSource.DataSet.Fields.Fields[0].FieldName It cannot be changed on an open table I probably have no choice but to use a separate table for each case. Share this post Link to post
Uwe Raabe 2057 Posted October 5, 2022 The FieldName is always taken from the database, so you cannot force that. You can change the Name and DisplayLabel after the fields are created. For static fields that is not a problem, but dynamic fields simply don't exist before Open. Therefore AfterOpen is a good place to do. The data type is derived from the type in the database and you have only limited influence on that. At the end, what you are doing is rather unusual, so I assume you are trying to solve another problem using a wrong approach. Share this post Link to post
Stano 143 Posted October 5, 2022 Thank you for your response I have already found out where the basic problem is. In my component. I used the solution using separate tables and the problem ran out for me right away. Share this post Link to post