Topic: About good practice....
Hello Dmitry and all other MVD fans,
I have to admit I am a bit confused. I've read so many things, tested so many functions and worked so much with MVD (which is a greeeeat tool), that I believe I'm begining to find my way decently around Delphi.
But... (of course, there is a but)
The application I'm building is huge. I've reached 1200 lines of code, and some procedures handle more than a 100 variables. And everything is working pretty much smoothly.
The question I'd like to ask today is this :
I'm handling a laaaaarge quantity of text, contained into a string, that I got like this :
source := HTTPGet(some URL);
This "source", is then assigned to various variables (name_source, url_source, sku_source...), because this way, I only call the HTTPGet function once and therefore it's faster (and I don't risk getting banned from the site I visit for server hamering).
I have to use all those variables containing the SAME text because, in order to find the info I need (based on HTML tags), I perform a lot of delete and copy operation to finally reach the text I want between specific tags.
To be precise, I use the same source text 9 times, because I'm looking for 9 different info on the same page, but the page is beeing destroyed each time I copy / delete part of it.
If you add to this all the if, else if , else I've added to the code in case there are (for example) not 1, not 2 but URL I want to grab... or even 0 in which case I have to handle the empty returned string before database saving...
Oooh, this works... but is it the right way to do it ?
I mean, keeping so many variables in memory... declaring in advance so many variables (you have to declare them up to the maximum elements you might encounter right ?)...
Questions :
About memory : after declaring 100 variables and assigning values to them, do I have to free memory, or destroy the variables, or do they die at the end of the procedure, or on closing of the form (after database injection) ?
About text handling : Is there a HTMLParser integrated to MVD, or do you plan to integrate one ? Wouldn't that be easier to walk the DOM and get directly to TAG ?
About SQLExecute : God, I do that so many times in my code... Do I have to close the SQL connexuion somewhere or the Form closing does it ?
About the large amount of text I'm handling through variables : Is it the right method ? Sould I assign that to a TStringList, or a TMemoryStream. I read about Dictionaries and the advantage of refereing to all my variables with only one name and indexes. Can I do the same thing with TStringList or TMemoryStream ?
I know that's a lot of questions, and I know you have other posts to answer, I apologize for that
I wish you all a good day
Cheers
Mathias
Each time I get a divorce, I keep the house
Zaza Gabor