Board index » cppbuilder » TgrahicControl descendent not visible on form

TgrahicControl descendent not visible on form


2007-08-10 12:58:43 PM
cppbuilder31
I have created a new graphic component (first one) and paint the image required but cannot get it to display the image on a form
What am I missing
 
 

Re:TgrahicControl descendent not visible on form

Quote
What am I missing
It is extremely difficult to diagnose a problem with your code when you
haven't shown your code.
The most common mistake that people make is to not set the Parent. Other
than that there are hundreds of possibilities.
- Clayton
 

Re:TgrahicControl descendent not visible on form

Quote
The most common mistake that people make is to not set the Parent. Other
than that there are hundreds of possibilities.

- Clayton


Thanks for the response Clayton
The component is very complex so I've included the basic outline
The component installs onto the Palette OK and will place on a Form showing the 4 dots to mark its size but no graphic.
This is the manual method of creating an istance etc I use to to debug it
You could just use a draw rectangle on something in the paintGuage function to test it
***************************************************
// Form H File
//---------------------------------------------------------------------------
#ifndef GuageTest1H
#define GuageTest1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "cfGuage.h"
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
private: // User declarations
public: // User declarations
tcfGuage* TorqueGuage;
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
*****************************************************
// Form CPP File
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "GuageTest1BAK.h"
#include "cfGuage.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
// #pragma link "cfGuage"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TorqueGuage = new tcfGuage(this);
TorqueGuage->Parent=this;
TorqueGuage->Left =0;
TorqueGuage->gSlopeY =100;
TorqueGuage->gSlopeX =100;
TorqueGuage->Height =400;
TorqueGuage->Width =1000;
TorqueGuage->gSlopeX =100; // Slope Multiplier
TorqueGuage->gSlopeY =100; //Slope Divider
TorqueGuage->gDisplScale =1;
TorqueGuage->ClearMaxFlg =1;
TorqueGuage->gHieght =80; // Height of the guage bar
TorqueGuage->MarginTop = 2;
TorqueGuage->gBend =200;
TorqueGuage->gWidth =10; // Margin Top to top of Bar
/*
TorqueGuage->PaintGuage();
TorqueGuage->DrawPos(400);
*/
}
//---------------------------------------------------------------------------
***********************************************
// New Component H File
//---------------------------------------------------------------------------
#ifndef cfGuageH
#define cfGuageH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
//---------------------------------------------------------------------------
class PACKAGE tcfGuage : public TGraphicControl
{
private:
int FTop;
int FLeft;
int FHeight;
int FWidth;
void __fastcall Paint(void) ;
.
.
.
protected:
public:
AnsiString UnitsText;
__fastcall tcfGuage(TComponent* Owner);
bool __fastcall PaintGuage(void);
bool __fastcall DrawPos(int Value);
.
.
.
__published:
__property int Top = { read=FTop, write=FTop, default=10 };
__property int Left = { read=FLeft, write=FLeft, default=0 };
__property int Heiht = { read=FHeight, write=FHeight, default=400 };
__property int Width = { read=FWidth, write=FWidth, default=1000 };
.
.
.
};
//---------------------------------------------------------------------------
#endif
**************************************************
// New Component CPP File
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "cfGuage.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(tcfGuage *)
{
new tcfGuage(NULL);
}
//---------------------------------------------------------------------------
__fastcall tcfGuage::tcfGuage(TComponent* Owner)
: TGraphicControl(Owner)
{
}
//---------------------------------------------------------------------------
namespace Cfguage
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(tcfGuage)};
RegisterComponents("Samples", classes, 0);
}
}
//---------------------------------------------------------------------------
bool __fastcall tcfGuage::PaintGuage(void)
{
bool RetVal=true;
int gTop;
gTop=Top+MarginTop;
Canvas->Pen->Color=clSilver;
Canvas->Pen->Width=6;
Canvas->Brush->Color=clRed;
Canvas->MoveTo(Left,gYStart);
.
.
.
Draw shapes etc
}
 

{smallsort}

Re:TgrahicControl descendent not visible on form

"SteveL" < XXXX@XXXXX.COM >wrote in message
Quote
private:
int FTop;
int FLeft;
int FHeight;
int FWidth;
You need to get rid of those completely.
Quote
void __fastcall Paint(void) ;
That needs to be in the 'protected' section instead.
Quote
__published:
__property int Top = { read=FTop, write=FTop, default=10 };
__property int Left = { read=FLeft, write=FLeft, default=0 };

__property int Heiht = { read=FHeight, write=FHeight,
default=400 };
__property int Width = { read=FWidth, write=FWidth,
default=1000 };
You need to get rid of those. TGraphicControl already inherits published
Left, Top, Width, and Height properies from TControl. You need to use those
instead of declaring your own.
Quote
gTop=Top+MarginTop;
<snip>
Canvas->MoveTo(Left,gYStart);
That is wrong. Those property values are relative to the control's Parent,
not to the control itself. You are drawing in the wrong area within your
Canvas.
Gambit
 

Re:TgrahicControl descendent not visible on form

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"SteveL" < XXXX@XXXXX.COM >wrote in message
news:46bc0d4b$ XXXX@XXXXX.COM ...

>Canvas->MoveTo(Left,gYStart);

That is wrong. Those property values are relative to the control's Parent,
not to the control itself. You are drawing in the wrong area within your
Canvas.


Gambit


Thanks for the help!
I can't find anything in the manual about this and cant work out
Where I should be drawing to, I assumed that the Canvas I was painting to was the TGraphicsControl->Canvas and that Top, Left etc. were likewise, but they all remain 0 even though I set them in the form Create
I'm baffled
Steve
 

Re:TgrahicControl descendent not visible on form

"SteveL" < XXXX@XXXXX.COM >wrote in message
Quote
I can't find anything in the manual about this and cant work out
Where I should be drawing to
You are supposed to be drawing starting at coordinates 0,0 rather than at
Left,Top.
Quote
I assumed that the Canvas I was painting to was the
TGraphicsControl->Canvas
It is.
Quote
and that Top, Left etc. were likewise
Don't use Left and Top at all in your drawing calculations.
Quote
they all remain 0 even though I set them in the form Create
That is probably due to the way you were incorrectly using them, which I
already pointed out to you.
Try this code instead:
--- GuageTest1.cpp ---
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
TorqueGuage = new tcfGuage(this);
TorqueGuage->Parent = this;
TorqueGuage->SetBounds(0, 0, 1000, 400);
TorqueGuage->MarginTop = 2;
// set drawing properties as needed...
}
--- cfGuage.h ---
class PACKAGE tcfGuage : public TGraphicControl
{
private:
bool __fastcall PaintGuage(void);
bool __fastcall DrawPos(int Value);
protected:
virtual void __fastcall Paint(void);
public:
__fastcall tcfGuage(TComponent* Owner);
//...
__published:
__property Height = { default=400 };
__property Width = { default=1000 };
//...
};
//--------------------------------------------------------------------------
-
#endif
--- cfGuage.cpp ---
#include "cfGuage.h"
__fastcall tcfGuage::tcfGuage(TComponent* Owner)
: TGraphicControl(Owner)
{
SetBounds(Left, Top, 400, 1000);
//...
}
void __fastcall tcfGuage::Paint(void)
{
//...
PaintGuage();
//...
}
bool __fastcall tcfGuage::PaintGuage(void)
{
bool RetVal = true;
int gTop = MarginTop;
Canvas->Pen->Color = clSilver;
Canvas->Pen->Width = 6;
Canvas->Brush->Color = clRed;
Canvas->MoveTo(0, gTop);
//...
return RetVal;
}
If you need further help with this, then you need to show more of your code.
Gambit
 

Re:TgrahicControl descendent not visible on form

Thanks very much!!!
It's funny how even after all these years one can do something silly and until it's pointed out you can't see it yourself
Regards Steve
"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"SteveL" < XXXX@XXXXX.COM >wrote in message
news:46bc4cee$ XXXX@XXXXX.COM ...

>I can't find anything in the manual about this and cant work out
etc....
Gambit