Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LIST MEMORY to cursor

Status
Not open for further replies.

Gerrit Broekhuis

Programmer
Aug 16, 2004
316
NL
Hi,

Is it possible to add the output of VFP’s List Memory into a cursor?

I don’t mean to put the content into a memo file, but I’m looking for a structured solution.
After all in memory things will be organized, so how do I get a similar structure in a cursor?

Regards, Gerrit
 
Off the top of my head, you could do something like this:

Code:
SET ALTERNATE TO c:\listmem.txt
SET ALTERNATE ON
LIST MEMORY
SET ALTERNATE OFF
SET ALTERNATE TO

CREATE CURSOR ListMem (varname c(27), scope c(15), datatype c(7), datavalue c(52))
APPEND FROM c:\listmem.txt TYPE sdf

That should give you a cursor with fields for the variable name, its scope, its data type and its value. It will also include a few spurious records, containing things like the number of variables defined and the number of variables available, but you could probably locate and delete those if necessary.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

I will check this next monday, when I’m back at work.

Regard, Gerrit
 
Gerrit,

If you don't want the cursor to contain records containing spurious information, such as the various headings and counts, add the following lines to the end of the above code:

Code:
DELETE FROM ListMem WHERE ;
  LEFT(Varname, 1) = SPACE(1) OR ;
  AT("Print System", Varname) > 0 OR ;
  AT("Menu and Pad", Varname) > 0 OR ;
  AT("Popup Definitions ", Varname) > 0 OR ;
  AT("Window Definitions ", Varname) > 0
  
* Un-comment the following lines if you also want to 
* remove system variables, such as _FOXCODE and _PAGENO
*!*	DELETE FROM ListMem WHERE ;
*!*	  LEFT(Varname, 1) = "_"

A couple of points: This code works with the English version of VFP. It might need modifying for other versions (not sure about that). Also, the code will also remove individual array elements from the cursor. You sill get the name of the array, but not the individual values.

I hope you find this useful.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

I tried your code today. In VFP.EXE it runs fine, I have tweaked the field width a bit, but this looks quite OK.

However, when I use the same code (tried yours as well) in a compiled exe with an ERROR 1999 command in a desktop button, the output is no longer put in the same fields. Somewhere the structure gets lost.
I haven't found a solution yet for this, as another error comes up in the errorhandler itself.

Another curious thing is that I get a lot more output from your code compared to:

Code:
List Memory Like *.* To File ccPDir+"\ERRORLOG\MEMORY.MEM" NOCONSOLE

Regards, Gerrit
 
Don't use *.*, that's useful in the context of file names, but doesn't give you any variables, names don't have dots in them. If you want all memory data, don't use a LIKE clause at all, just LIST MEMORY TO FILE...

Your use of .MEM file extension points out you rather would like to use SAVE MEMROY and RESTORE. That has its pros and cons.

Also notice neither of these possibilities drills down object properties. If your goal is to safe the full state of your application, there's no easy one size fits all. An idea would be to give any class you define a method to save it's own state and use that with something cascading from some root starting points like an application object. SetAll() is a nice function for that.

Chriss
 
Another curious thing is that I get a lot more output from your code compared to:

Yes, that's right. If you omit the LIKE clause, you also get the system variables that I mentioned above, as well as menus, popups and windows. If you include the LIKE clause, you only get memory variables. And it makes no difference whether you include [tt]LIKE *.*[/tt] or simply [tt]LIKE *[/tt] - the result is the same (at least, that's the case in my tests).

You also said:

when I use the same code (tried yours as well) in a compiled exe with an ERROR 1999 command in a desktop button, the output is no longer put in the same fields. Somewhere the structure gets lost.

I assume that means that you want to do the LIST MEMORY from within your error-handler, and you are executing an ERROR command to force the error-handler to fire.

If that's right, that's perfectly reasonable. I use [tt]LIST MEMORY LIKE * TO FILE[/tt] in my error-handlers in all my applications, and it always works as expected. You say the structure gets lost. What exactly are you seeing in the output file?

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

Yes, without “LIKE……” I do get the right (full) results.
I’ve set memowidth to 8192 and the output is now acceptable. And with lower values like 1024 it’s still OK.

Regards, Gerrit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top