Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Yuri Rubinov
  Where is Yuri Rubinov?
 Pennsylvania - United States
 Yuri Rubinov
 To: Jorge Luis Vejerano
  Where is Jorge Luis Vejerano?
 Jorge Luis Vejerano
Subject: RE: General Fields to Memo Fields
Thread ID: 78319 Message ID: 78514 # Views: 2 # Ratings: 0
Version: Visual FoxPro 9 Category: Databases, Tables and SQL Server
Date: Tuesday, October 04, 2005 6:29:26 PM         

> >
> > Jorge,
> >
> > As far as I see, you have WordPad.Document objects for all records except one, which has Word.Document object. You can check it with
> >
> > ?oForm.myOLe1.oleclass
> >
> > I am afraid that with WordPad you cannot perform automation; as far as I know, its interface is "wild" and unpredictable. I spent some time to work on it, but I was not able to do anything useful with all methods I know.
> >
> >
> > Best Wishes,
> >
> > Yuri Rubinov
> Searching in Google, I found the following:
> *****************************************************************
> General and Memo Fields
> For those who know how hard is to manage general fields, especially writing them to the SQL Server image field or into the ADO object binary data field, following are some tips. Before tips itself I posted here also some problems description so you will understand better how they can help and where to use them.
> Memo and General fields in VFP table stores by the same way - 4-byte pointer in the DFB table that follows to the chunk in the fpt file. Both memo field and general field allows any binary data stored there, include chr(0) and many other characters that are not allowed by otehr database systems that manage memo fields (SQL Server text field type tends to corrupt binary data stored in it).
> The problem is that VFP allows to work free with memo fields providing a wide set of the string functions (see StringHandling), but don't allows to store memo field content in the image field of the SQL Server using SPT because it mapped to general field in VFP. You can do this however, using mapping field type in the remote view. What about ADO? Another problem is that there are no any command in VFP that allows to store content of general field into the file or get it as a binary string. For example assume we have SQL Server database that stores some binary data in the image field (images). When we run a query from VFP for such field, it will return as a general field. Now, how to save a content of general field to file (image) and show image on form? Again, use of remote views only...
> All problems above could be solved very easy. Using the fact that memo and general fields are stored in the VFP table files by the same way, we can easy change a field type... by low-level functions, causing getting content of general field as we use memo field (assumed that genera/memo field is a first field in the table):
> * Save image to memo field
> * FiltoStr(...) than replace
> * or append memo ... from ...
> * change memo field type to general
> ll = fopen("F:\ttt.dbf",12)
> fseek(ll,43)
> fwrite(ll,'G')
> fclose(ll)
> * now you can save it to image field type
> * above could be used also to get general field from SQL Server using ADO
> And opposite operation:
> * get data from serevr in general field
> ...
> * change general field type to memo
> ll = fopen("F:\ttt.dbf",12)
> fseek(ll,43)
> fwrite(ll,'M')
> fclose(ll)
> * now you can read it as a text!
> * use this way also to store general field on the server using ADO
> There is also assumption that working with general fields should be avoided at all cost. Its very wrong assumption. General field in VFP provides such functionality that is unique - it does not exists in any other database systems. Well, you can assume it is dead, but look to following example.
> Say, you require to print a MS Graph chart. Well, its easy to put a chart to the form control and populate it and design it using its objects model and properties. Now, what if you need to include it into VFP report? Well, the solution here is only to use General field. However, little of programmers use that. Why? The simple reason is that you cannot use control's object model to edit chart in the general field. Well, you cannot do this directly. However, you can make an invisible form, put OLEBoundControl on it, bind it to your general field with chart and using "MyForm.OleBoundControl1.Object..." syntax you can edit enything you want in that chart! The greatest thing is that changes by such way are really stored in the general field and could be used in report. So now we can make an empty chart in the general field, change it as we want by useing OLEBoundControl on the form that is outside of visible portion of VFP main window, than show it in report... Pretty COOL! Now, using this approach, you can prepare for printing any OLE Object by this way and print it! For eample, this way RTF content could be easy printed in the VFP report using Word OLE object in general field. Just replicate it for all records and change each general field to store RTF content for each record.
> The same applies to all other OLE controls. You can use Object property of the OLE Bound control to edit properties of any object in it across all objects tree of OLE object. You can do this for MS Word documents, for example. And all changes are stored in the general field where you can use it again and again.
> *****************************************************************
> I try but I failed
> Jorge Luis Vejerano
> IT Solutions and Support

I am afraid I do not understand what did you "try but I failed", and how all what you posted above about the general field on GOOGLE is related to your particular case where you have WordPad documents.
Different ole objects require different approaches.
For instance, for WordPad the MyForm.OleBoundControl1.Object is NULL. So you cannot use it.

There is a lot what was said about general field limitations and alternatives. You may search the forum here for "general" and review discussions.

Meanwhile you may play with the code below. It does not work frequently showing the WordPad MFC Application Error. Clearly there is a conflict somewhere between applications, or in the way they share the PC memory/clipboard. Clipboard is not accessible until the WordPad is closed, new record is loaded and olecontrol is refreshed.
Therefore in the code below you will see strange combinations of skip -1 and skip 1.

Also, check your version of WordPAd for short keys; sendkeys method below is for "my" English version.

USE c:\reclamos
oShell = CreateObject("WScript.Shell")
lcWindowTitle="WordPad Document"


local oForm
oForm = Createobject('_Form',Genfiedname)

*WITH oForm.myOLe1
* .visible=.t.
* .Height = 2000
* .Width = 2000


GO top

REPLACE descrip2 WITH ""

IF llupdate and NOT EMPTY(_cliptext)
REPLACE descrip2 WITH _cliptext

llupdate= .f.

IF NOT LOWER(oForm.myOLe1.oleclass)="wordpad.document"
* ?oForm.myOLe1.oleclass

DO WHILE SECONDS()-lnstart <10 AND ;
NOT oShell.AppActivate(lcWindowTitle)
WAIT WINDOW TIMEOUT 1.0 "Loading "+lcWindowTitle+"... Please, wait ..."

IF oShell.AppActivate(lcWindowTitle)
oShell.SendKeys("%El^C") && Select all and Copy
oShell.SendKeys("%Fx") && Close WordPad





Define Class _Form As Form
this.myole1.ControlSource = ALIAS()+'.'+pGenfieldName

Best Wishes,

Yuri Rubinov


General Fields to Memo Fields Posted by Jorge Luis Vejerano @ 9/30/2005 6:32:38 PM
RE: General Fields to Memo Fields Posted by Yuri Rubinov @ 9/30/2005 7:35:46 PM
RE: General Fields to Memo Fields Posted by Jorge Luis Vejerano @ 9/30/2005 9:26:13 PM
RE: General Fields to Memo Fields Posted by Jorge Luis Vejerano @ 10/3/2005 7:03:57 PM
RE: General Fields to Memo Fields Posted by Yuri Rubinov @ 10/3/2005 8:50:59 PM
RE: General Fields to Memo Fields Posted by Jorge Luis Vejerano @ 10/3/2005 11:40:16 PM
RE: General Fields to Memo Fields Posted by Yuri Rubinov @ 10/4/2005 3:30:28 PM
RE: General Fields to Memo Fields Posted by Jorge Luis Vejerano @ 10/4/2005 5:29:10 PM
RE: General Fields to Memo Fields Posted by Yuri Rubinov @ 10/4/2005 6:29:26 PM
RE: General Fields to Memo Fields Posted by Jorge Luis Vejerano @ 10/4/2005 6:48:51 PM