OriginObject::SetMemory

Description

Set/Create named binary storage

Syntax

BOOL SetMemory( LPCSTR lpcszName, vector<byte> & vb, BOOL bSetDirty = FALSE )

Parameters

lpcszName
[input] Storage name
vb
[input] vector of bytes to be saved. Use NULL to clean the storage, Ex2 example below.
bSetDirty
[input] Set dirty project.

Return

TRUE if success

Examples

EX1

string OriginObject_SetMemory_Support_Ex1(LPCSTR lpcszFilename)
{
    string str;
    stdioFile ff;
    bool bRet = ff.Open(lpcszFilename, file::modeRead);
    if(!bRet)
    {
        out_str("file not found!");
        return str;
    }
    
    string strTemp;
    while(ff.ReadString(strTemp))
        str += strTemp + "\r\n";
    
    ff.Close();
    
    return str;
}

void OriginObject_SetMemory_Ex1()
{
    Page pg = Project.Pages();
    if(!pg)
        return;
    
    string strFilename = GetAppPath() + "origin.ini";
    string strFileContent = OriginObject_SetMemory_Support_Ex1(strFilename);
    
    vector<byte> vb;
    if(strFileContent.GetBytes(vb) && pg.SetMemory("Test", vb))
        out_str("Saving origin.ini into page.info done");
}

Ex2

void OriginObject_Storage_Ex2(string strPageName = "Book1", string strStorageName = "SomeJunk")
{
    Page pg = Project.Pages(strPageName);
    if(pg)
    {
        Tree tr; 
        tr.Company.strVal = "ACME Corp";
        pg.PutBinaryStorage(strStorageName, tr); 
 
        vector<string> vsNames;
        pg.GetStorageNames(vsNames);
                for(int ii = 0; ii < vsNames.GetSize(); ii++)
                {
                        printf("%d %s\n", ii, vsNames[ii]);
                }
        
        pg.SetMemory(strStorageName, NULL); // to set the storage memory as NULL
        out_str("del "+ strStorageName);
        
        pg.GetStorageNames(vsNames);
        for(ii = 0; ii < vsNames.GetSize(); ii++)
        {
                printf("%d %s\n", ii, vsNames[ii]);
        }
    }
    else
        printf("Not this page named %s in project\n", strPageName);
}

Remark

Set/Create named binary storage

See Also

OriginObject::GetMemory

header to Include

origin.h