Board index » cppbuilder » Why...

Why...


2005-04-08 04:02:07 PM
cppbuilder109
Hi everybody:
1.this Project can't run,but i fix
Method one : bool Active put DefFunc Reca after ,and Complete
,can run this project
Method two :remove #include <winsock2.h>,and Complete ,can run
this project
why ?
//-------------------------------------
// MyTestLib.h
//--------------------------------------
#ifndef MyTestLibH
#define MyTestLibH
#include <winsock2.h>
namespace Mynamespace
{
typedef void (__closure *DefFunc)( );
class M
{
public:
M(){};
~M(){};
void S();
public:
bool Active;
DefFunc Reca;
};
}
using namespace Mynamespace;
#endif
//------------------------------
//MyTestLib.CPP
//------------------------------
#pragma hdrstop
#include "MyTestLib.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
void M::S()
{
Reca();
};
// ------------------------
// Unit1.H
//------------------------
#ifndef Unit1H
#define Unit1H
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "MyTestLib.h"
//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
M testObj;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void Rec();
};
//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;
//--------------------------------------------------------------------------
-
#endif
//------------------------------
// Unit1.CPP
//---------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
void TForm1::Rec()
{
int a;
a = 10;
};
void __fastcall TForm1::Button1Click(TObject *Sender)
{
testObj.Reca = Rec;
testObj.S();
}
//--------------------------------------------------------------------------
-
 
 

Re:Why...

etjon wrote:
Quote
Hi everybody:

1.this Project can't run,but i fix
Method one : bool Active put DefFunc Reca after ,and
Complete ,can run this project
Method two :remove #include <winsock2.h>,and Complete ,can
run this project

why ?

//-------------------------------------
// MyTestLib.h
//--------------------------------------
#ifndef MyTestLibH
#define MyTestLibH
#include <winsock2.h>

namespace Mynamespace
{

typedef void (__closure *DefFunc)( );

class M
{
public:
M(){};
~M(){};
void S();

public:
bool Active;
DefFunc Reca;

};
}
using namespace Mynamespace;
#endif
My guess (without having tried to compile your code) is that
the above using directive causes some interaction with something
named DefFunc that is declared in winsock2.h.
In practice, it's usually a VERY good idea to avoid any using
namespace directives in header files (and to use fully scoped
names of types within header files eg in class declarations).
 

Re:Why...

Hi Rob :
Thank you,your response, i try to replay DefFunc ,but result is the
same..
Can you help me to see my code ,I live in taiwan ,so my english is
not good .....sorry
I Post My All Code ...
//--------------------------------------------------------------------------
--------------------------------------
//-------------------------------------
// MyTestLib.h
//--------------------------------------
#ifndef MyTestLibH
#define MyTestLibH
#include <winsock2.h>
namespace Mynamespace
{
typedef void (__closure *DefFunc)( );
class M
{
public:
M(){};
~M(){};
void S();
public:
bool Active;
DefFunc Reca;
};
}
using namespace Mynamespace;
#endif
//------------------------------
//MyTestLib.CPP
//------------------------------
#pragma hdrstop
#include "MyTestLib.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
void M::S()
{
Reca();
};
// ------------------------
// Unit1.H
//------------------------
#ifndef Unit1H
#define Unit1H
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "MyTestLib.h"
//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
M testObj;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void Rec();
};
//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;
//--------------------------------------------------------------------------
-
#endif
//------------------------------
// Unit1.CPP
//---------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
void TForm1::Rec()
{
int a;
a = 10;
};
void __fastcall TForm1::Button1Click(TObject *Sender)
{
testObj.Reca = Rec;
testObj.S();
}
//--------------------------------------------------------------------------
-
"Rob" < XXXX@XXXXX.COM >bl news: XXXX@XXXXX.COM
g...
Quote
etjon wrote:

>Hi everybody:
>
>1.this Project can't run,but i fix
>Method one : bool Active put DefFunc Reca after ,and
>Complete ,can run this project
>Method two :remove #include <winsock2.h>,and Complete ,can
>run this project
>
>why ?
>
>//-------------------------------------
>// MyTestLib.h
>//--------------------------------------
>#ifndef MyTestLibH
>#define MyTestLibH
>#include <winsock2.h>
>
>namespace Mynamespace
>{
>
>typedef void (__closure *DefFunc)( );
>
>class M
>{
>public:
>M(){};
>~M(){};
>void S();
>
>public:
>bool Active;
>DefFunc Reca;
>
>};
>}
>using namespace Mynamespace;
>#endif

My guess (without having tried to compile your code) is that
the above using directive causes some interaction with something
named DefFunc that is declared in winsock2.h.

In practice, it's usually a VERY good idea to avoid any using
namespace directives in header files (and to use fully scoped
names of types within header files eg in class declarations).


 

{smallsort}

Re:Why...

Hi!
etjon wrote:
Quote
Hi Rob :
Thank you,your response, i try to replay DefFunc ,but result is the
same..
Can you help me to see my code ,I live in taiwan ,so my english is
not good .....sorry
Please cut your quotes!
I cannot see the error. It compiles fine with BCB5.
Frank
 

Re:Why...

Hi Frank:
I Use BCB6 and package 4 ,It compiles is OK,
But to Run ,can see the error,access XXXX.......
and fix to Method1 or Method2 ,is Complete ok and Running Ok.
Help me .....Help me ...thank....
1.this Project can't run,but i fix
Method one : bool Active put DefFunc Reca after ,and Complete,can
run this project
Method two :remove #include <winsock2.h>,and Complete ,can runthis
project
why ?
//-------------------------------------
// MyTestLib.h
//--------------------------------------
#ifndef MyTestLibH
#define MyTestLibH
#include <winsock2.h>
namespace Mynamespace
{
typedef void (__closure *DefFunc)( );
class M
{
public:
M(){};
~M(){};
void S();
public:
bool Active;
DefFunc Reca;
};
}
using namespace Mynamespace;
#endif
//------------------------------
//MyTestLib.CPP
//------------------------------
#pragma hdrstop
#include "MyTestLib.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
void M::S()
{
Reca();
};
// ------------------------
// Unit1.H
//------------------------
#ifndef Unit1H
#define Unit1H
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "MyTestLib.h"
//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
M testObj;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void Rec();
};
//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;
//--------------------------------------------------------------------------
-
#endif
//------------------------------
// Unit1.CPP
//---------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
void TForm1::Rec()
{
int a;
a = 10;
};
void __fastcall TForm1::Button1Click(TObject *Sender)
{
testObj.Reca = Rec;
testObj.S();
}
"Frank Birbacher" < XXXX@XXXXX.COM >???
Quote
Hi!

etjon wrote:
>Hi Rob :
>Thank you,your response, i try to replay DefFunc ,but result is
the
>same..
>Can you help me to see my code ,I live in taiwan ,so my english
is
>not good .....sorry

Please cut your quotes!

I cannot see the error. It compiles fine with BCB5.

Frank

 

Re:Why...

On Sat, 9 Apr 2005 09:23:30 +0800, etjon wrote:
Quote
why ?
Probably because (as Rob pointed out) your DelFunc clashes with something
else. Also, as Rob pointed out, don't use namespace within the header, use
fully qualified names.
--
Good luck,
liz
 

Re:Why...

Hi... Liz:
But I try to fix DefFunc to MyDefFunc ,
It's Result is the same....
why ...
"Liz Albin" < XXXX@XXXXX.COM >???
Quote
On Sat, 9 Apr 2005 09:23:30 +0800, etjon wrote:

>why ?

Probably because (as Rob pointed out) your DelFunc clashes with something
else. Also, as Rob pointed out, don't use namespace within the header,
use
fully qualified names.
--
Good luck,

liz
 

Re:Why...

Hi!
Even if I run the code I can still not observe any error. But
well, I have BCB5 instead of 6. And operating system may also matter.
etjon wrote:
Quote
But I try to fix DefFunc to MyDefFunc ,
It's Result is the same....
Maybe you should get rid of "using namespace" and try to rename
other things, too, like:
namespace MyNamespace {
class MyTest
{
public:
//default ctor and dtor
callMyFunc() { tryThisFunc(); }
bool isReallyActive;
MyDefFunc tryThisFunc;
};
} //namespace MyNamespace
using MyTest;
Frank
 

Re:Why...

Hi Frank :
(1).
I run the code ,in BCB6 and Windows Server 2000,
Please you will callMyFunc's code not put in header ,beacse i try ,it's ok ,
but you put callMyFunc's code to Cpp,It's complete to run,Have a accect
XXXX.....Error .....
And tryThisFunc is from outside VLC method to assign,
Can you try My code....,Help Me ..again .Thank you....
(2).Today I see newsgroup have a mail,It's use static to define variable,and
i fix my code
it's run very good ,not any Error ...Why . ths method is right or not good ?
//-------------------------------------
// MyTestLib.h
//--------------------------------------
#ifndef MyTestLibH
#define MyTestLibH
#include <winsock2.h>
namespace Mynamespace
{
typedef void (__closure *DefFunc)( );
class M
{
public:
M(){};
~M(){};
void S();
public:
bool Active;
static DefFunc Reca;
};
DefFunc M::Reca;
}
using namespace Mynamespace;
#endif
(3).
SourceCode :
//-------------------------------------
// MyTestLib.h
//--------------------------------------
#ifndef MyTestLibH
#define MyTestLibH
#include <winsock2.h>
namespace Mynamespace
{
typedef void (__closure *DefFunc)( );
class M
{
public:
M(){};
~M(){};
void S();
public:
bool Active;
DefFunc Reca;
};
}
using namespace Mynamespace;
#endif
//------------------------------
//MyTestLib.CPP
//------------------------------
#pragma hdrstop
#include "MyTestLib.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
void M::S()
{
Reca();
};
// ------------------------
// Unit1.H
//------------------------
#ifndef Unit1H
#define Unit1H
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "MyTestLib.h"
//--------------------------------------------------------------------------
-
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
M testObj;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void Rec();
};
//--------------------------------------------------------------------------
-
extern PACKAGE TForm1 *Form1;
//--------------------------------------------------------------------------
-
#endif
//------------------------------
// Unit1.CPP
//---------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
void TForm1::Rec()
{
int a;
a = 10;
};
void __fastcall TForm1::Button1Click(TObject *Sender)
{
testObj.Reca = Rec;
testObj.S();
}
"Frank Birbacher" < XXXX@XXXXX.COM >???
Quote
Hi!

Even if I run the code I can still not observe any error. But
well, I have BCB5 instead of 6. And operating system may also matter.

etjon wrote:
>But I try to fix DefFunc to MyDefFunc ,
>It's Result is the same....

Maybe you should get rid of "using namespace" and try to rename
other things, too, like:

namespace MyNamespace {

class MyTest
{
public:
//default ctor and dtor
callMyFunc() { tryThisFunc(); }

bool isReallyActive;
MyDefFunc tryThisFunc;
};

} //namespace MyNamespace

using MyTest;

Frank

 

Re:Why...

Craig Leidy wrote:
Quote
... put a pool within spitting distance of the ocean?
It's to collect the spit that the onshore breeze brings back to it.
Quote
www.youtube.com/watch

Anyway... it's a really cool pool.
Yes, lovely. At 35 meters deep, it's an Atlantean wet dream. :-)
--
The Doctor
But they that eat wheatgrass shall renew their strength;
they shall mount up with wings as eagles;
they shall run, and not be weary;
and they shall walk, and not faint. --The Doctor
--
borland.public.off-topic exists as a runoff for unwanted posts in the
technical groups. Enforcement of rules is deliberately minimal but
Borland reserves the right to cancel posts at any time, for any
reason, without notice.
 

Re:Why...

Craig Leidy wrote:
Quote
... put a pool within spitting distance of the ocean?
According to the report, "In Chile the beaches are notoriously
dangerous, with rough waves and strong rip surrents."
--
Emil
--
borland.public.off-topic exists as a runoff for unwanted posts in the
technical groups. Enforcement of rules is deliberately minimal but
Borland reserves the right to cancel posts at any time, for any
reason, without notice.
 

Re:Why...

Craig Leidy wrote:
Quote
Anyway... it's a really cool pool.
Cool, but I don't think it's really 35 meters deep. :)
--
Emil
--
borland.public.off-topic exists as a runoff for unwanted posts in the
technical groups. Enforcement of rules is deliberately minimal but
Borland reserves the right to cancel posts at any time, for any
reason, without notice.
 

Re:Why...

Emilio Lizardo wrote:
Quote
but I don't think it's really 35 meters deep. :)
I assumed she meant 35m wide but this says 115 feet deep:
www.dailymail.co.uk/news/article-509718/Try-making-splash-worlds-largest-swimming-pool--1-000-yards-long.html
--
In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.
-Douglas Adams
--
borland.public.off-topic exists as a runoff for unwanted posts in the
technical groups. Enforcement of rules is deliberately minimal but
Borland reserves the right to cancel posts at any time, for any
reason, without notice.
 

Re:Why...

"Craig Leidy" < XXXX@XXXXX.COM >wrote:
Quote
... put a pool within spitting distance of the ocean?

www.youtube.com/watch

Anyway... it's a really cool pool.
It's safer for swimmers. Ever been caught in a rip? It's not fun, and
if you panic, you're screwed.
--
borland.public.off-topic exists as a runoff for unwanted posts in the
technical groups. Enforcement of rules is deliberately minimal but
Borland reserves the right to cancel posts at any time, for any
reason, without notice.
 

Re:Why...

Craig Leidy wrote:
Quote
... put a pool within spitting distance of the ocean?
If I 1) Lived near the ocean, 2) could afford it and 3) loved to swim (I
do), I certainly would. I love to walk or run along the ocean or just be
near it, but I absolutely hate to be in it and dislike only slightly less
being on it.
--
R.
--
borland.public.off-topic exists as a runoff for unwanted posts in the
technical groups. Enforcement of rules is deliberately minimal but
Borland reserves the right to cancel posts at any time, for any
reason, without notice.