Article View: cn.bbs.comp.program
Article #2089Re: c++ builder help!
From: �����п�
Date: Sun, 01 Feb 1998 00:00
Date: Sun, 01 Feb 1998 00:00
127 lines
4845 bytes
4845 bytes
I have done it myself!
>1��c++ builder �����ʹij�����ڳ�Ϊ����ģʽ�Ի�����
---> ShowModel();
>2��ʲô����ɸ㶨ע���
//***********************************************
// Written by Mr. Michael Jia 1998-01-31
//***********************************************
#include <vcl\vcl.h>
#include <vcl\registry.hpp>
#pragma hdrstop
#include "testr.h"
//--------------------------------------------------------------------------
-
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString path,font,color;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::exitClick(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::saveClick(TObject *Sender)
{ TRegistry *regtable ;
regtable=new (TRegistry);
/*************************************************************
1.Install Soft must be put here:
HKEY_LOCAL_MACHINE\Software\yourCompany\yourrProduct\ver1.0
2.If your software support ole must be put here:
HKEY_LOCAL_MACHINE\Software\Classes
3.Data you use must be put here:
HKEY_CURRENT_USER\Software\MyCompany\MyProduct\1.0\...
<<my sample is
HKEY_CURRENT_USER\Software\MichaelJia
Path
Font
Color
>>
Notice: CreateKey(OpenKey) & CloseKey must be pair.
**************************************************************/
if (regtable->OpenKey("Software",false)==true) //change RootKey
{regtable->RootKey=regtable->CurrentKey;
//Now RootKey is HKEY_LOCAL_MACHINE\Software
regtable->CloseKey();
}
else {MessageBox(0,"Change RootKey Error!!!","message",MB_OK);
return ;
}
if(regtable->OpenKey( "MichaelJia",false)==true) //save
{regtable->WriteString("Path",path->Text);
regtable->WriteString("Font",font->Text);
regtable->WriteString("Color",color->Text);
regtable->CloseKey();
}
else{
if( regtable->CreateKey("MichaelJia")==true)
{//if the first time just create the KEY
regtable->CloseKey(); //after you create it ,you must close it
//for reopenning to write !!!!!
MessageBox(0,"First time ,MichaelJia created!","message",MB_OK);
//set default values
regtable->OpenKey("MichaelJia",false);
regtable->WriteString("Path","Hello,World");
regtable->WriteString("Font","C++ Builder");
regtable->WriteString("Color","My name is Michael Jia");
regtable->CloseKey();
}
else
{MessageBox(0,"Write error,other program locks the
Registry","message",MB_OK);
}
};
// regtable->CloseKey(); //close registry table
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::loadClick(TObject *Sender)
{
TRegistry *regtable ;
regtable=new (TRegistry);
if (regtable->OpenKey("Software",false)==true) //change RootKey
{regtable->RootKey=regtable->CurrentKey;
//Now RootKey is HKEY_LOCAL_MACHINE\Software
regtable->CloseKey();
}
else {MessageBox(0,"Change RootKey Error!!!","message",MB_OK);
return ;
}
if(regtable->OpenKey( "MichaelJia",false)==true) //save
{
path->Text=regtable->ReadString("Path");
font->Text=regtable->ReadString("Font");
color->Text=regtable->ReadString("Color");
regtable->CloseKey();
}
else {
MessageBox(0,"Read error!!! \nMaybe other program locks the Registry or you
don't save it first!","message",MB_OK);
};
//regtable->CloseKey(); //close registry table
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::changeClick(TObject *Sender)
{ AnsiString saves;
saves=path->Text;
path->Text=font->Text;
font->Text=color->Text;
color->Text=saves;
}
//--------------------------------------------------------------------------
-
Technical Details
Message-ID:
<6autci$8gt$1@clinux.ml.org>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6au41l$54p$2@clinux.ml.org>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: fc86e,ed71b7d769e65e7d X-Google-Attributes: gidfc86e,public From: "�����п�" <jia@gicom2000.com> Subject: Re: c++ builder help! Date: 1998/02/01 Message-ID: <6autci$8gt$1@clinux.ml.org> X-Deja-AN: 320809007 References: <6au41l$54p$2@clinux.ml.org> X-Server-Date: 31 Jan 1998 10:11:30 GMT X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3 Organization: Chinese Linux User Group Newsgroups: cn.bbs.comp.program