Aleniko


Hi all;

A pretty simple question:

lets assume I have a class which is used for entering a range (customers, dates etc). It consists of 2 text boxes. I am dropping this class into a form which is producing a report.
My question: What is the common/best way of accessing the control source of the textboxes in the class I can do any of the following:

- Access them directly by their relative names (ie this.parent. etc)

- Any time I want to use the class in a form, create 2 form properties and assign the control source of the 2 text boxes to these properties.

- create the above properties in the class level and address them again as relative names within the form.

- Something entirely different which I've missed...

Thanks for your input.


Re: Proper practice - using class properties in forms/reports.

Tamar E. Granor


My preference for this kind of thing is to use container-level properties as the ControlSources. Then, the form can talk to the container, which talks to the textboxes.

Tamar




Re: Proper practice - using class properties in forms/reports.

Naomi Nosonovsky

The class needs to be a black box and return all the information through the methods, not even through the properties. E.g. the class may have GetRange() method, for example.




Re: Proper practice - using class properties in forms/reports.

Aleniko

Tamar, Naomi;

So if I'm running a report limited by range of date, my call would be something like this

report form myform for trdate >= thisform.container.txtFromDate.value .AND. trdate <= thisform.container.txtToDate.value

Or do I call the sugested 'getrange' method of the container Can you give me some detail re this method

Thanks.




Re: Proper practice - using class properties in forms/reports.

CetinBasoz

Something like this:

define class GetRange as container

start = null

end = null

add object txtStart as textBox with ControlSource = "this.parent.start", ....

add object txtEnd as textBox with ControlSource= "this.parent.end", ....

*....

enddefine

When reporting:

select ... from ... where someField between thisform.getRange.Start and thisform.getRange.End into cursor crsReport

report form myReport





Re: Proper practice - using class properties in forms/reports.

Naomi Nosonovsky

I built such classes for my search form. The parent class has some base methods, one of them to return Where expression as a string. Each subclass has this method modified. So, when I needed Search functonality I just placed few subclasses on the form, set properties and in form's method concatenated Where expression from these criterion objects.

That's the basic idea, my form didn't even need to know specifics, such as Start/End dates, the validation was also built in.

If you want send me tomorrow an e-mail, I'll send you this classlibrary.

I also have few nice classes in UT Downloads which I used long time ago as Search criteria too. I then re-used it in one of my newer applications (with minor modifications).





Re: Proper practice - using class properties in forms/reports.

Tamar E. Granor

Rather than referring to the textbox in the report command, I would add properties to the container class: dStart and dEnd, for example, and make those the ControlSource for the textboxes. Then, I'd use:

REPORT FORM MyForm ;
FOR BETWEEN(trDate, ThisForm.Container.dStart, ThisForm.Container.dEnd)

The form shouldn't even know there are textboxes involved. Hide all that detail in the container class. That has the advantage that you can change the way the container class works (for example, using the ActiveX Date and Time Picker instead of textboxes) without having to change any of the forms that use the class.

Tamar




Re: Proper practice - using class properties in forms/reports.

Naomi Nosonovsky

Hi Tamar,

See my idea in my message. You don't even need to know what the criterion container is about. It will simply return you a where expression suitable to Search or report FOR clause. Of course, you would have to macro expand which is a disadvantage.





Re: Proper practice - using class properties in forms/reports.

Aleniko

Thanks for he good idea Naomi.

Alen.




Re: Proper practice - using class properties in forms/reports.

Tamar E. Granor

Yeah, I saw that. That's good if you know that the only thing you'll use the control for is building queries. My approach works any time you might want to select start and end dates. Both are valid.

Tamar




Re: Proper practice - using class properties in forms/reports.

Aleniko

Thank you Tamar, Naomi, Cetin and everyone else for all the detailed and different ideas.

Alen.




Re: Proper practice - using class properties in forms/reports.

dereck27

Thanks for he good idea.