Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can not remove objects in the Form's Load?
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00341285
Message ID:
00341369
Views:
32
Fred,

>>>>>>> I have a form, which has two grids, only one of them is really used, and other should be removed. The removing code was in Form's Init method and it works just fine. When I put the same code into Load method, it failes. Both grids have all columns controlsource set in design-time.
>>>>>>>
>>>>>>> I'm thinking about put NODEFAULT in Grid Init method, if certain conditions are met. Is there simpler approach?
>>>>>>>
>>>>
>>>>>>Couple of thoughts. I believe the objects are not yet instantiated when the form Load fires, hence, your error. I think you should be able to test in the grid Init and just return .F. from the Init to keep the grid from instantiating.
>>>>>
>>>> Ok, I tried it. Two problems I found: 1) I'm still having an error, if it's not a correct structure, so this doesn't help.
>>>>
>>>>2) For some reason, in the grid Init methods it could not recognize constants, defined in the include file, if I'm in the debug mode...
>>>>
>>>>What are the other suggestions?
>>>>
>>
>>>What do you mean by "not a correct structure"? What error are you getting?
>>
>> 'Error loading file - record number 4. grdBldMstr2 .ControlSource: Variable 'ownerzip5' is not found.
>>
>>The problem with include file might be temproral (at was not able to reproduce it, so I think, something was wrong with the path settings in that time).
>>
>>Anyway, there is the problem: I have two grids on a form with all columns ControlSource set in design-time. When I run my form, I use only one of them, depending on some conditions. How can I (if it possible) prevent execution of Grid Init and all it's childs Init.
>>
>>Another possible solution - save these grids as two classes and then instead of removing - add either of them. But how can I do this, if they're already on the form (I mean, create a class)? And, besides, it seems to me that this solution is combersome...
>>
>>TIA
>
>Put code in the Init of each grid that checks for some condition (a form property), that you set in your form Load method. Then each grid can decide for itself whether it should RETURN .F. in it's own Init.


I did this exactly already. But, it seems like grid's child Init method executes before grid Init method itself. So, this approach doesn't work, because, as I said, all columns are defined in design-time, I mean, each column has ControlSource property set in design-time. Threfore, if my form received the table with different structure, one of column Init method failed, I assume. I traced in the debug: it successfully goes through Load method, then immediately stops. At this point Grid.Init method isn't even executed.

Another solution is to temproraly delete these grids, add them again and place remove grid in one of the other form's control Init method. But this solution beats OOP conception, I think...

What else can I try? BTW, this is probably not the case in our app, because the table will always have all required fields, but if this problem could be easily solved, I prefer to solve it...
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform