Home › Forums › kbmMemTable › Short form field name??
- This topic has 9 replies, 2 voices, and was last updated 3 years, 11 months ago by
kimbomadsen.
-
AuthorPosts
-
-
January 8, 2022 at 21:51 #56145
ijbranch@outlook.com
ParticipantHi Guys,
I can access a field in the normal way – kbmTable.FieldByName(‘SomeField’).AsString.
Having defined the field ‘SomeField’ in the kbmTable, is there any way to use the short form?? – kmbTableSomeField.AsString.
If not would it be possible to implement?
Regards & TIA,
Ian
-
January 19, 2022 at 12:15 #56160
kimbomadsen
KeymasterHi,
Yes if you setup the fields at designtime, then fields will be directly available.
Mind you that if you load data in from external sources, you should either not load structure/definitions (because that would redefine fields, invalidating your designtime fields), or if the fields are the same, you can try to set AutoUpdateFieldVariables to true before the load.
/Kim -
January 21, 2022 at 21:51 #56168
ijbranch@outlook.com
ParticipantTks Kim.
If the loaded structure/definitions are exactly the same as the pre-defined fields, will that still invalidate?
Ian
-
January 21, 2022 at 22:10 #56169
ijbranch@outlook.com
ParticipantHi Kim,
You did answer my question, I just didn’t read it right. 🙁
So, If the fields are predefined and I have this..
{code}
…
//
Open;
//
mtCompany.LoadFromDataSet(Company, [mtcpoStructure, mtcpoOnlyActiveFields, mtcpoProperties, mtcpoFieldIndex, mtcpoDontDisableIndexes, mtcpoIgnoreErrors]);
//
Close;
//
end;
//
mtCompany.Open;
//
CurrentEurekaLogOptions.SendSMTPClientHost := mtCompanySMTPServer.AsString;
CurrentEurekaLogOptions.SendSMTPClientPort := mtCompanySMTPPort.AsInteger;…
{code}
If I make “AutoUpdateFieldVariables” True then it fails at “CurrentEurekaLogOptions.SendSMTPClientHost := mtCompanySMTPServer.AsString;”
If I remove “mtcpoStructure” with “AutoUpdateFieldVariables”, it works fine.
If I remove “mtcpoStructure” with “AutoUpdateFieldVariables” False, it also works fine.
What did you expect “AutoUpdateFieldVariables” to do?
Regards & Tks,
Ian
-
January 21, 2022 at 22:25 #56170
ijbranch@outlook.com
ParticipantOK. I thought I had it sorted.. 🙁
It all looks OK in the Datamodule (dmQ) where the above code is located.
But, in the mainform code it doesn’t like code like the following..
” sQuoteReportName := Trim(dmQ.mtCompanyCompanyInit.AsString) + ‘General Quote’;”
I have to make it..
“sQuoteReportName := Trim(dmQ.mtCompany.FieldByName(‘CompanyInit’).AsString) + ‘General Quote’;”
defeating the purpose. 🙁
Am I doing something wrong??
Regards & TIA,
Ian
-
January 23, 2022 at 17:32 #56173
kimbomadsen
KeymasterGenerally the advice is not to load a new structure into any dataset if you expect to reuse designtime form field variables.
Usually changing the structure makes the designtime form field variable point to something invalid, as the field that originally existed no longer exists.So the above is the rule of thumb.
Make a choice:
– Load new structure, and use FieldByName to access fields
– Use design time field variables directly, but in that case do not load a new structure.AutoUpdateFieldVariables is an attempt to automatically update the designtime form field variables as far as is possible, when a new (but exact matching) structure is loaded into the memory table. If there are any differences in field count, names or types, one or more of the field variables may be pointing to invalid data.
/Kim
-
January 30, 2022 at 08:57 #56184
ijbranch@outlook.com
ParticipantThanks Kim,
I have settled for using the field variables directly, defining them at design time.
The kbmmemtable component is in a Datamodule called dmQ.
Using the field variables directly in the datamodule works fine.
What doesn’t work is trying to access the field variables from the Main form..
i.e. sQuoteReportName := Trim(dmQ.mtCompanyCompanyInit.AsString)
Even though all the fields have been loaded into mtCompany at design time.
Am I missing some nuance??
Regards & TIA,
Ian
-
February 1, 2022 at 22:41 #56186
kimbomadsen
KeymasterHi,
The way kbmMemTable is trying to allocate new field variable instances, is to first actually remove the components, last first, referenced to by the field variables. Essentially they are owned by the form/datamodule itself.
Then it will recreate a new set in the opposite order, with the same names as the old ones.
That is a “trick” to make it work, but it is an unsafe method, that I could easily see fail when something are using the field variables from outside.Since you have already defined the structure at designtime, and you are relying on the field variables from various places, the best option is not to try to create a new structure when loading data. Simply set sfLoadDef to false in the Options of the streamformat component.
Then fields with matching names will be loaded and if additional fields, not already defined at designtime, exists, they will not be loaded.
/Kim
-
-
February 2, 2022 at 01:15 #56188
ijbranch@outlook.com
ParticipantHi Kim,
Given your comment above, I suspect I am not using kbmmemtable correctly. 🙁
In my datamodule (dmQ) I have the Database Tables, including the Company Table, it is an ElevateDB database, and only a kbmmemtable component (mtCompany), no stream format component.
In dmQ I have the following code..
{code}
Company.Open;
//
mtCompany.LoadFromDataSet(Company, [mtcpoOnlyActiveFields, mtcpoProperties, mtcpoFieldIndex, mtcpoDontDisableIndexes, mtcpoIgnoreErrors]);
//
Company.Close;
{code}The fields are pre defined in mtCompany at design time.
I don’t have a StreamFormat component. I am not loading from any .bin or .csv file..
Ian
-
February 2, 2022 at 12:49 #56189
kimbomadsen
KeymasterHi,
Ok… then I misunderstood. In this case you are not using mtcpoStructure, which is good as that would trigger the same scenario as I explained related to the streamformat above, by calling CreateTableAs.
However you do include mtcpoProperties, mtcpoFieldIndex, mtcpoOnlyActiveFields which should only optionally be provided when using mtcpoStructure, and not used in other scenarios, since at least mtcpoProperties will make changes to the designtime defined fields, while the rest are superfluous.
/Kim
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.
