Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
PRIVATE vs Hard-coding cursor name
Message
 
 
To
15/03/2019 08:50:22
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01667233
Message ID:
01667261
Views:
38
>>I have a function MyReport() where the local variables were declared and the value of SYS(2015) assigned. Then these cursors were populated.
>>Then, in order, to convert the report to a PDF, another function MyXfrx() was called. Inside the function MyXfrx() the report was being changed to PDF.
>>The problem, I realized later was that in the report I was using the names of the cursors. E.g.
>>
>>evaluate( cursorBand1 + ".myfield" )
>>
>>and it would cause a run-time error.
>>I changed the variables (in MyReport()) to PRIVATE and it got around the problem.
>>I am not comfortable with a PRIVATE. So, when I have time, I will change the variables to hard-coded cursors.
>
>Actually, that kind of thing is the only use for Private that I am comfortable with - when you pass down a procedure/function call something that contains a dependency on a variable, then that variable needs to be in scope where it's used. In my case, it's various sql command strings containing ?parameters, which I don't run in the same procedure where the parameters are assigned, but pass them to a specialized object (call it SqlHandler or something such). That object needs to see these parameters or else the SQLexec() will break when parser tries to replace them with values. So private they are, and I often write a comment explaining why they are private.
>
>As long as you're disciplined with this and declaring private is an exception used when really needed, you'll be fine.

I agree and instinctively (because I am still a newbie to VFP and programming :) realize that this use of PRIVATE is ok.
But I am a perfectionist (bad quality for an entrepreneur) and will probably change my code anyway.

As far as your case, using SQLexec(), I agree. Although I have a function for the SQLExec() and pass parameters as variables. And I know that I am in danger of SQL injection attack. But I have learned to live with this threat.
Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform