Article View: borland.public.cppbuilder.nativeapi
Article #6785Re: value of class object
From: JD
Date: Mon, 11 Apr 2005 02:48
Date: Mon, 11 Apr 2005 02:48
129 lines
6011 bytes
6011 bytes
"Boguslaw Fries" <boguslaw.fries@polivision.it> wrote:
>
> [...] I dont know exactly which is the appropriate newsgroup
> for it. Sorry ;)
There is a specific group (so I'm told) for asking that exact
question :-0. However, I can tell you this group is specific
to win32 API calls and the borland.public.cppbuilder.language.cpp
group is specific to language issues which your question most
definately is.
> I declare the class:
>class Myclass
>{
>private:
> int iVal;
> float fVal;
>public:
> Myclass( int i ) { iVal = i;}
> Myclass( float f ) { fVal = f; }
>}
>Now in my program:
>Myclass M( 5 );
>int X;
>
>X = M; // X should obtain value 5
That is not the case (that X == 5) and i doubt that that will
even compile. The line:
Myclass M( 5 );
creates an instance of Myclass named 'M', passing 5 to it's
constructor (and does nothing else with it). The value of 'M'
is in reality a 32bit pointer that must be correctly dereferenced
to access class members or methods.
>How to implement extra things to do it?
Here's a sample class that I use to get version info from my
application. All you have to do is #include the header and add
the lines (note that it support multiple languages as well):
TVersionInformation Info;
if( Info.Available )
{
Caption = Info.ProductName;
Version->Caption = "Version: " + Info.FileVersion;
......
}
//-------------------------------------------------------------
#ifndef VerInfoH
#define VerInfoH
//-------------------------------------------------------------
struct TVersionInformation
{
private:
char *Buffer;
public:
bool Available;
AnsiString CompanyName;
AnsiString FileDescription;
AnsiString FileVersion;
AnsiString InternalName;
AnsiString LegalCopyright;
AnsiString LegalTrademarks;
AnsiString OriginalFilename;
AnsiString ProductName;
AnsiString ProductVersion;
AnsiString Comments;
TVersionInformation()
{
Buffer = NULL;
Available = false;
CompanyName = "";
FileDescription = "";
FileVersion = "";
InternalName = "";
LegalCopyright = "";
LegalTrademarks = "";
OriginalFilename = "";
ProductName = "";
ProductVersion = "";
Comments = "";
DWORD Handle, Size = ::GetFileVersionInfoSize( Application->ExeName.c_str(), &Handle );
if( Size )
{
UINT Length;
LPVOID lpBuffer;
unsigned short *LangCharSet;
Buffer = new char[ Size ];
LPVOID pBlock = (LPVOID) Buffer;
if( ::GetFileVersionInfo( Application->ExeName.c_str(), Handle, Size, pBlock ) )
{
if( ::VerQueryValue( pBlock, "\\VarFileInfo\\Translation", (void **)&LangCharSet, &Length ) )
{
AnsiString Prefix;
Prefix.sprintf("\\StringFileInfo\\%04x%04x\\", LangCharSet[0], LangCharSet[1] );
if( ::VerQueryValue( pBlock, AnsiString( Prefix + "CompanyName" ).c_str(), &lpBuffer, &Length ) ) CompanyName = (char *) lpBuffer;
if( ::VerQueryValue( pBlock, AnsiString( Prefix + "FileDescription" ).c_str(), &lpBuffer, &Length ) ) FileDescription = (char *) lpBuffer;
if( ::VerQueryValue( pBlock, AnsiString( Prefix + "FileVersion" ).c_str(), &lpBuffer, &Length ) ) FileVersion = (char *) lpBuffer;
if( ::VerQueryValue( pBlock, AnsiString( Prefix + "InternalName" ).c_str(), &lpBuffer, &Length ) ) InternalName = (char *) lpBuffer;
if( ::VerQueryValue( pBlock, AnsiString( Prefix + "LegalCopyright" ).c_str(), &lpBuffer, &Length ) ) LegalCopyright = (char *) lpBuffer;
if( ::VerQueryValue( pBlock, AnsiString( Prefix + "LegalTrademarks" ).c_str(), &lpBuffer, &Length ) ) LegalTrademarks = (char *) lpBuffer;
if( ::VerQueryValue( pBlock, AnsiString( Prefix + "OriginalFilename" ).c_str(), &lpBuffer, &Length ) ) OriginalFilename = (char *) lpBuffer;
if( ::VerQueryValue( pBlock, AnsiString( Prefix + "ProductName" ).c_str(), &lpBuffer, &Length ) ) ProductName = (char *) lpBuffer;
if( ::VerQueryValue( pBlock, AnsiString( Prefix + "ProductVersion" ).c_str(), &lpBuffer, &Length ) ) ProductVersion = (char *) lpBuffer;
if( ::VerQueryValue( pBlock, AnsiString( Prefix + "Comments" ).c_str(), &lpBuffer, &Length ) ) Comments = (char *) lpBuffer;
Available = true;
}
}
}
}
~TVersionInformation()
{
if( Buffer ) delete [] Buffer;
}
};
//-------------------------------------------------------------
#endif
>In fact I could use Variant class, but intentionally I do not.
Smart man.
~ JD
Technical Details
Message-ID:
<4259d766$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<42566160$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,1f4e1214f81b2544 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Re: value of class object Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 172.147.75.161 References: <42566160$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <4259d766$1@newsgroups.borland.com> Date: 10 Apr 2005 18:48:22 -0800 X-Trace: newsgroups.borland.com 1113184102 207.105.83.66 (10 Apr 2005 18:48:22 -0800) Lines: 130 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail