1919
FAQ [OOP]
On this page are placed the answers to questions which I cruelly (or easy) found, I do not think, that the answers are exhausting, and if you will find, that something not conform to your representations, let's discuss and we shall find the best decisions... Besides frequently answer can depend on the version as OS and Visual FoxPro, to check up all on all versions and platforms for me simply excessively. Initially this list was only for VFP 5.0, while now it only VFP 7.0/8.0, I could somewhere and miss a mention of the version, and if you will find discrepancies, inform me, please.

 

Q: From what to begin and how practically to use the OOP approach at programming in Microsoft Visual FoxPro, after we were determined with structure of the customer data? 

A: First of all, on my sight, it is necessary to mention the following moments about data:
It is necessary to be overlook all tables and for each of fields to give value to heading of a field (Caption) and to give definition of a field (Field comment) on a tab Fields, if you it have not made yet. Thus it is necessary also to specify the Russian names of the tables (aliases of the tables) (Name) and to give definitions to the tables (Table comment) on a tab Table. It is necessary to note, that though version Visual FoxPro 5.0 and allows to enter verbose aliases of the tables, it is better nevertheless to have one-word aliases received by combined of words by means of a symbol '_'. Concerning the names of fields, it is necessary to tell, that though for the tables placed in the database Visual FoxPro there is a restriction in 128 symbols, early or late there can be a necessity of carry of the data on SQL Server, where, certainly, there are restrictions (for example, for MS SQL Server 6.5 lengths of a field 30 symbols, besides the names of fields, certainly are used at programming on server [Transact-SQL], where the first symbol '@' designates working local variable, reducing thus actual length of a field up to 29 symbols), moreover, the name of an index in Visual FoxPro 5.0 makes only 10 symbols, others will be rejected, if you will create an index, being based on a field.
Further look after, please, that for all of primary keys the functions returning new values of keys (default value) were determined, same most it is necessary to do and for all values of foreign keys in each of the tables. The code of the appropriate functions should be placed in a database as the stored procedures. Believe, that it not a problem of the front client to try correctly to generate new values of keys, it by all means should be by property of the data, instead of client. An example of the simple stored procedure allowing to receive new values of keys, you can find in Vfp\Samples\Tastrade\Data\Testdata.dbc - FUNCTION NewID(). Concerning values for foreign keys, I think, that is possible to adhere to the following rule: in any table being a source given for other tables, the first record, with initial value of a key primary key, - is value by default for all other tables, i.e. just this value should be determined as property default value for all fields foreign keys.
Pass once again on all fields of your tables and look critically: whether it is impossible at a stage of input, using a mask of a field (Input mask) to exclude only formal mistakes of input; define also format of display of the data (Format); and if there is a necessity, create functions of the control of the data of a level of a field (Rule) and define the text of the message (Message), given out at infringement of these rules on a tab Fields. If there is a necessity of check of a condition between values of different fields of one record of the table, by all means it is necessary to take advantage of function of the control of the data of a level of the table (Rule) and define the text of the message (Message), this rule, given out at infringement, on a tab Table.
At last, go on environment of editing of a database (Modify database ... Exclusive) and, by causing dialogue of the control of integrity of the data (Database/Edit Referential Integrity…), establish necessary options of the control (Restrict | Cascade | Ignore) on events of changes of the data (Update, Delete, Insert) between all connected pairs tables. If the pairs, necessary to you, tables have not appeared in dialogue of the control of integrity of the data, go in editing the appropriate tables and establish to it a primary key, then define intertabulared relation, i.e. foreign key. Here pertinently once again to repeat, that, using function TABLEUPDATE() at the buffered source of the data, it is necessary always to analyze returned value of this function, and if it will matter .F. It is necessary in addition to use function AERROR() for specification of the reasons of failure of system in saving of the data and to notify on it the user, by means of distribution of the appropriate warning.
Further, for creation actually application on the initial stage you can take advantage, at least, two preparations: by a class cApplication, created by Application Wizard (Tools \Wizards\All …) or class tastrade in an example Tasmanian Traders Sample (Vfp\Samples \Tastrade\Libs\ Main.vcx), inherited from Application in Vfp\Samples\Tastrade\Libs\Tsgen.vcx. In the first case it is required to you, most likely, being inherited from cApplication, to create an own class of the application, adding in it necessary functional-specific from classes Tastrade Application, for example support Toolbar. Certainly, you can write all from zero point independently, however, most likely thus you will find out, that write that is already written in the above mentioned classes.
At last, for maintenance "standard functional" works with the form, the best variant consists in use of a class tsBaseForm and inherited from tsMaintForm from library Vfp\Samples\Tastrade\Libs\Tsbase.vcx. Certainly, if essentially it is not pleasant to you, how the forms in an example Tasmanian Traders Sample works, you can not adhere to my advice and to write all from zero independently. However believe me, that you should write the same methods, and very much I doubt, that they will was essentially differ under the contents, when you will force them to work. Certainly, the mentioned above classes have only minimally necessary functional, and you will need them to develop and to improve as required. If you do not plan to use OOP style of programming and client/server technology for work with the data, probably, you really need to think of use any of other tools of programming of databases for building applications for the clients.

Q: How in the instance of a class tsBaseForm from Vfp\Samples\Tastrade\Libs\Tsbase.vcx to prevent use Toolbar, as in the given concrete case of the form at me is not present necessity for functions of navigation between records? 

A: It is enough to change value of property cToolbar of this class from the name of a class tsToolbar (working on default) to an empty line. If thus you nevertheless have necessity for use others, distinct from navigating methods, as: AddNew, Save, Restore etc., is required to you alternative ways of a call of these methods, for example, by means of addition in the form of command buttons. Further, in a lot of methods, for example AddNew, there is unconditional use of property Enabled of the button cmdNew, therefore it is necessary to ensure of the conditional manipulation to this property: IF TYPE ('oApp') = 'O' AND !EMPTY(ThisForm.cToolbal), by making the appropriate updating in all similar cases in methods of the given class.

Q: I have a visual class-container and it is impossible in runtime to change "geometry" of the elements for it's instance. For want of to attempt of modifications happens something completely not clear. Whether there is any variant it to make? 

A: Create a temporary instance of a class Form (oMyTempForm = CreateObject (" Form ")) and create a copy of your class - container as instance of a class Form (using a method oMyTempForm.AddObject ("oMyNewObj1", "MyBaseObj")). On completion of modifications save an improved copy of a class in your classes library. (oMyTempForm.oMyNewObj1. SaveAsClass (MyClassLibName, MyNewClassName [, Description]))

Q: Unexpectedly has come across a problem: the function PEMSTATUS() with attribute 0 in exe works only if the checked Debug info is on, and always .F. otherwise. It is valid so? 

A: Hm... Really there is such problem.

Q: How change the Quick Start form to the own form in VFP-application created by Application Wizard? 

A: In the instance of your class (app_application) (derivative from _framewk._application), if in Application Builder the Quick Start is checked, then we have:< br > Class: app_application
Properties:
cstartupformclass = app_favoritepicker
lStartupForm = .T.
... Now it is necessary to replace this on app_MyClassFirstForm, however such class, should be correct in the method DoDocumentPickerDialog() in app_application (<- _framewk._application)
... and to simplify a problem, it is possible to do next:
    - add in app_application an additional property type: This.lContinue
    - and overwrite method DoDocumentPickerDialog() on something of a type:

LPARAMETERS tcClass,tcClassLib,tlAlternateMode
IF !This.lContinue
      This.lContinue = .T.
      RETURN This.DoForm("MyFirstFormSCX")
ELSE
      RETURN DODEFAULT(tcClass,tcClassLib,tlAlternateMode)
ENDIF
 
 
Hosted by uCoz