Board index » cppbuilder » Using TScrollBox Problems scrolling.

Using TScrollBox Problems scrolling.


2004-12-09 04:50:21 PM
cppbuilder85
Hi,
I'm using a TScrollBox with items (panels) that are added at run time.
the first time i create the item's it all go's well, from the scond time
there is a problem thing are created the other way around and scrolling is
working upside down
Is there any solution for this??
jvdn.
 
 

Re:Using TScrollBox Problems scrolling.

Jochanan wrote:
Quote
I'm using a TScrollBox with items (panels) that are added at run time.
the first time i create the item's it all go's well, from the scond time
there is a problem thing are created the other way around and scrolling is
working upside down
Is there any solution for this??
This is to vague. What is for instance "the other way round" ?
Please show code that demonstrates the problem.
Post code that compiles and links.
Keep the amount of code as small as possible.
Hans.
 

Re:Using TScrollBox Problems scrolling.

"hans galema" < XXXX@XXXXX.COM >schreef in bericht
Quote
Jochanan wrote:

>I'm using a TScrollBox with items (panels) that are added at run time.
>the first time i create the item's it all go's well, from the scond time
>there is a problem thing are created the other way around and scrolling
>is working upside down
>Is there any solution for this??

This is to vague. What is for instance "the other way round" ?
Please show code that demonstrates the problem.

Post code that compiles and links.
Keep the amount of code as small as possible.

Hans.
I can't send all the code
but i can show some part of it.
the main problem is that i have an order class (selfdefiend class) witch
contains data.
to show the data i dont't want to use a table but frame so i can change the
layout at any time without being forsed to use a table. so i have a frame
with some data field on it.
When i add my frames to a TScrollBox
code
if (FOrders)
{
int i = 0;
while (i < FOrders->Size )
{
clsOrder *lcurOrder = FOrders->GetOrderAtPos(i++);
TFrameOrderRow * lcurItem = new TFrameOrderRow(scbOrderItems,
lcurOrder,Mediator);
lcurItem->Parent = scbOrderItems;
lcurItem->Name += "00" +String(i);
lcurItem->Align = alTop;
}
}
the first time they are all correct in place and the key up and down are
working fine,
after i remove the frames and add them again
code for the remove
void __fastcall TFrameOrderList::RemoveOrderClients()
{
int l =0;
while (scbOrderItems->ComponentCount>l)
{
TComponent * lComp = scbOrderItems->Components[l];
if (dynamic_cast<TFrameOrderRow *>(lComp) != NULL)
{
TFrameOrderRow * lOrderRow;
lOrderRow = dynamic_cast<TFrameOrderRow *>(lComp);
lOrderRow->Parent = NULL;
delete lOrderRow;
}
else
{
l++;
}
}
}
I persume that in one or an other way I don't remove my frames in the right
way.
I hope you can go on with this information.
jvdn
 

{smallsort}

Re:Using TScrollBox Problems scrolling.

Jochanan wrote:
Quote
I can't send all the code
You were not asked to do that. You were explicitly asked to send as little
as possible.
Quote
When i add my frames to a TScrollBox
Noe you have Tframe's ? I thougth you had TPanels.
Quote
if (FOrders)
{
int i = 0;
while (i < FOrders->Size )
{
clsOrder *lcurOrder = FOrders->GetOrderAtPos(i++);
TFrameOrderRow * lcurItem = new TFrameOrderRow(scbOrderItems,
How do you think that we can compile this ? FOrders ? clsOrder ?
Quote
the first time they are all correct in place and the key up and down are
working fine,
What is the correct order ? Which key up/down ?
Quote
after i remove the frames and add them again

code for the remove
void __fastcall TFrameOrderList::RemoveOrderClients()
{
int l =0;
while (scbOrderItems->ComponentCount>l)
{
TComponent * lComp = scbOrderItems->Components[l];
Ayiii.. You declare a one character variable "int l" ?
How will you disdinguish a l from a 1 at first glance ?
What is scbOrderItems ?
The way you loop though the components looks wrong.
Now you start at the first one. Better start with the
last on. If you then delete components the others stay in place.
int compnr = ... ->ComponentCount;
while ( --compnr>= 0 )
{
TFrameOrderRow *lOrderRow =
dynamic_cast<TFrameOrderRow *>(scbOrderItems->Components[compnr]);
if ( lOrderRow )
delete lOrderRow;
}
Hans.
 

Re:Using TScrollBox Problems scrolling.

Hi Hans Galgema,
I just created a special case that only has the problem.
if you compile the code just use the <TAB>key until the scrolbox get the
focus, then use the arow keys and see the results.
I took already some of your recommentadions into considerarions.
the file names are abit fuzie but the class names are clear.
I hope you can stil take a look at is.
Regards jvdn
here is the code because i can't send an attachment.
the Project File and the DFM files are missing
if u need them i can mail them to your one mail adres or if you can tell me
how to post an attachment i'll do that
regards Jochanan
file one
HPP///////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "Unit4.h"
//---------------------------------------------------------------------------
//----------------------------------------------------------------------
class TFormOrderList : public TForm
{
__published: // IDE-managed Components
public: // User declarations
__fastcall TFormOrderList(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TFormOrderList *FormOrderList;
//---------------------------------------------------------------------------
#endif
CPP
/////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormOrderList *FormOrderList;
//---------------------------------------------------------------------------
__fastcall TFormOrderList::TFormOrderList(TComponent* Owner)
: TForm(Owner)
{
TFrameOrderList *fol = new TFrameOrderList(Owner);
fol->Parent = this;
}
//---------------------------------------------------------------------------
File 2
HPP/////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
class TFrameOrderRow : public TFrame
{
__published: // IDE-managed Components
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
void __fastcall FrameEnter(TObject *Sender);
void __fastcall FrameExit(TObject *Sender);
void __fastcall FrameClick(TObject *Sender);
private: // User declarations
clsOrder * Data;
TColor OldColor, OldTextColor;
public: // User declarations
__fastcall TFrameOrderRow(TComponent* Owner,clsOrder *);
};
//---------------------------------------------------------------------------
extern PACKAGE TFrameOrderRow *FrameOrderRow;
//---------------------------------------------------------------------------
#endif
CPP/////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit4.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFrameOrderRow *FrameOrderRow;
//---------------------------------------------------------------------------
__fastcall TFrameOrderRow::TFrameOrderRow(TComponent* Owner, clsOrder *
pOrder)
: TFrame(Owner),Data(pOrder)
{
Label1->Caption = Data->Name;
Label2->Caption = Data->Date.DateString();
Label3->Caption = Data->Amount;
}
//---------------------------------------------------------------------------
void __fastcall TFrameOrderRow::FrameEnter(TObject *Sender)
{
OldColor = Color;
Color = clHighlight;
OldTextColor = Font->Color;
Font->Color = clRed; //clHighlightText;
Label1->Color = Color;
Label1->Font->Color = Font->Color;
Label3->Color = Color;
Label3->Font->Color = Font->Color;
Label2->Color = Color;
Label2->Font->Color = Font->Color;
}
//---------------------------------------------------------------------------
void __fastcall TFrameOrderRow::FrameExit(TObject *Sender)
{
Color = OldColor;
Font->Color = OldTextColor;
Label1->Color = Color;
Label1->Font->Color = Font->Color;
Label3->Color = Color;
Label3->Font->Color = Font->Color;
Label2->Color = Color;
Label2->Font->Color = Font->Color;
}
//---------------------------------------------------------------------------
void __fastcall TFrameOrderRow::FrameClick(TObject *Sender)
{
this->SetFocus();
}
//---------------------------------------------------------------------------
File 3
HPP/////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#ifndef Unit3H
#define Unit3H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "unit4.h"
//---------------------------------------------------------------------------
class TFrameOrderList : public TFrame
{
__published: // IDE-managed Components
TButton *btnClearList;
TButton *btnBuildList;
TScrollBox *scbOrderItems;
void __fastcall btnBuildListClick(TObject *Sender);
void __fastcall btnClearListClick(TObject *Sender);
void __fastcall scbOrderItemsEnter(TObject *Sender);
private: // User declarations
clsOrderList * FOrders;
int getSize();
private: // User declarations
public: // User declarations
__fastcall TFrameOrderList(TComponent* Owner);
__fastcall ~TFrameOrderList();
void __fastcall RemoveOrderClients();
void __fastcall AttachOrderClients(bool pBottomToTop);
};
//---------------------------------------------------------------------------
extern PACKAGE TFrameOrderList *FrameOrderList;
//---------------------------------------------------------------------------
#endif
CPP/////////////////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit3.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFrameOrderList *FrameOrderList;
//---------------------------------------------------------------------------
__fastcall TFrameOrderList::TFrameOrderList(TComponent* Owner)
: TFrame(Owner)
{
FOrders = new clsOrderList();
}
//---------------------------------------------------------------------------
__fastcall TFrameOrderList::~TFrameOrderList()
{
delete FOrders;
}
//---------------------------------------------------------------------------
void __fastcall TFrameOrderList::RemoveOrderClients()
{
int k =0;
while (scbOrderItems->ComponentCount - k -1>= 0)
{
TComponent * lComp =
scbOrderItems->Components[scbOrderItems->ComponentCount - 1 - k];
if (dynamic_cast<TFrameOrderRow *>(lComp) != NULL)
{
TFrameOrderRow * lOrderRow;
lOrderRow = dynamic_cast<TFrameOrderRow *>(lComp);
lOrderRow->Parent = NULL;
delete lOrderRow;
}
else
{
k++;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TFrameOrderList::AttachOrderClients(bool pBottomToTop)
{
if (FOrders)
{
if (pBottomToTop)
{
int i = 0;
while (i < FOrders->Size )
{
clsOrder *lcurOrder = FOrders->GetOrderAtPos(i++);
TFrameOrderRow * lcurItem = new TFrameOrderRow(scbOrderItems,
lcurOrder);
lcurItem->Parent = scbOrderItems;
lcurItem->Name += "00" +String(i);
lcurItem->Align = alTop;
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TFrameOrderList::btnBuildListClick(TObject *Sender)
{
clsOrder * Order1 = new clsOrder("AAP",TDateTime(2004,12,15),2000);
clsOrder * Order2 = new clsOrder("NOOT",TDateTime(2004,12,14),3000);
clsOrder * Order3 = new clsOrder("Mies",TDateTime(2004,12,13),5000);
FOrders->AddOrder(0,Order1);
FOrders->AddOrder(0,Order2);
FOrders->AddOrder(0,Order3);
this->AttachOrderClients(true);
Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TFrameOrderList::btnClearListClick(TObject *Sender)
{
this->RemoveOrderClients();
delete FOrders;
FOrders = new clsOrderList();
Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TFrameOrderList::scbOrderItemsEnter(TObject *Sender)
{
if (scbOrderItems->ComponentCount)
{
if (dynamic_cast<TFrameOrderRow *>( scbOrderItems->Components[0]) !=
NULL)
{
TFrameOrderRow * frm = dynamic_cast<TFrameOrderRow
*>(scbOrderItems->Components[0]);
frm->FrameClick(this);
}
}
}
//---------------------------------------------------------------------------
File 4
HPP////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#include <vcl.h>
#ifndef Unit4H
#define Unit4H
//---------------------------------------------------------------------------
class clsOrder : public TObject
{
public:
AnsiString Name;
TDateTime Date;
long Amount;
long OrderID;
public:
clsOrder(AnsiString pName, TDateTime pDate,long Amount);
clsOrder(clsOrder *);
};
//----------------------------------------------------------------------
class clsOrderList
{
TStringList *Orders;
long LastOrderId;
int __fastcall getSize()const { return Orders->Count; };
public:
clsOrderList();
~clsOrderList();
void AddOrder(long pOrderID, clsOrder *pOrder);
clsOrder * GetOrderAtPos(int pPos);
clsOrder * GetOrder(long pOrderid);
__property int Size = {read = getSize};
};
#endif
CPP//////////////////////////////////////////////////////////////////////////////////////
//---------------------------------------------------------------------------
#pragma hdrstop
#include "Unit4.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
clsOrder::clsOrder(AnsiString pName, TDateTime pDate,long pAmount):
OrderID(0L), Name(pName), Date(pDate), Amount(pAmount)
{
}
//----------------------------------------------------------------------
clsOrder::clsOrder(clsOrder *pOrder)
{
Name = pOrder->Name;
Date = pOrder->Date;
Amount = pOrder->Amount;
OrderID = pOrder->OrderID;
}
//----------------------------------------------------------------------
clsOrderList::clsOrderList()
{
Orders = new TStringList;
LastOrderId = 0L;
}
//----------------------------------------------------------------------
clsOrderList::~clsOrderList()
{
if (Orders)
{
while(Orders->Count)
{
int i = Orders->Count -1;
clsOrder * tmp = (clsOrder *)Orders->Objects[i];
Orders->Delete(i);
delete tmp;
}
delete Orders;
Orders = NULL;
}
}
//----------------------------------------------------------------------
void clsOrderList::AddOrder(long pOrderID, clsOrder *pOrder)
{
if (pOrderID != 0)
{
Orders->AddObject(String(pOrderID),pOrder);
}
else
{
LastOrderId++;
Orders->AddObject(String(LastOrderId),pOrder);
}
}
//----------------------------------------------------------------------
clsOrder * clsOrderList::GetOrderAtPos(int pPos)
{
return (clsOrder *)Orders->Objects[pPos];
}
//----------------------------------------------------------------------
clsOrder * clsOrderList::GetOrder(long pOrderId)
{
int k = Orders->IndexOf(String(pOrderId));
return GetOrderAtPos(k);
}
//----------------------------------------------------------------------
"hans galema" < XXXX@XXXXX.COM >schreef in bericht
Quote
Jochanan wrote:

>I can't send all the code

You were not asked to do that. You were explicitly asked to send as little
as possible.


>When i add my frames to a TScrollBox

Noe you have Tframe's ? I thougth you had TPanels.

>if (FOrders)
>{
>int i = 0;
>while (i < FOrders->Size )
>{
>clsOrder *lcurOrder = FOrders->GetOrderAtPos(i++);
>TFrameOrderRow * lcurItem = new TFrameOrderRow(scbOrderItems,

How do you think that we can compile this ? FOrders ? clsOrder ?
This is what I ment FOrders is a shell around a TStringlist and clsOrder
are some long's AnsiStrings toegether.
Quote

>the first time they are all correct in place and the key up and down are
>working fine,
I want to be able to use the keybord. when the TScrollBox hes the focus
and I use the <Arrow down>Key VK_DOWN i get to the next item. When I use
the <Arrow up>key VK_UP i get to the privios item. when I'm at the top it
Quote

What is the correct order ? Which key up/down ?

>after i remove the frames and add them again
>
>code for the remove
>void __fastcall TFrameOrderList::RemoveOrderClients()
>{
>int l =0;
>while (scbOrderItems->ComponentCount>l)
>{
>TComponent * lComp = scbOrderItems->Components[l];


Ayiii.. You declare a one character variable "int l" ?
How will you disdinguish a l from a 1 at first glance ?

What is scbOrderItems ?

The way you loop though the components looks wrong.
Now you start at the first one. Better start with the
last on. If you then delete components the others stay in place.

int compnr = ... ->ComponentCount;

while ( --compnr>= 0 )
{
TFrameOrderRow *lOrderRow =
dynamic_cast<TFrameOrderRow
*>(scbOrderItems->Components[compnr]);

if ( lOrderRow )
delete lOrderRow;
}

Hans.
 

Re:Using TScrollBox Problems scrolling.

Jochanan wrote:
Quote
I hope you can stil take a look at is.
here is the code because i can't send an attachment.
Indeed you cannot add attachments in this newsgroup. But you can
in the attachments newsgroup. Please zip the project and place it in
the attachmentsgroup:
borland.public.attachments
Then I will have a look.
Hans.
 

Re:Using TScrollBox Problems scrolling.

"Jochanan" < XXXX@XXXXX.COM >schreef in bericht news:...
Quote

"hans galema" < XXXX@XXXXX.COM >schreef in bericht
news:41b82826$ XXXX@XXXXX.COM ...
>Jochanan wrote:
>
>>I'm using a TScrollBox with items (panels) that are added at run time.
>>the first time i create the item's it all go's well, from the scond time
>>there is a problem thing are created the other way around and scrolling
>>is working upside down
>>Is there any solution for this??
>
>This is to vague. What is for instance "the other way round" ?
>Please show code that demonstrates the problem.
>
>Post code that compiles and links.
>Keep the amount of code as small as possible.
>
>Hans.

I can't send all the code
but i can show some part of it.

the main problem is that i have an order class (selfdefiend class) witch
contains data.
to show the data i dont't want to use a table but frame so i can change
the
layout at any time without being forsed to use a table. so i have a frame
with some data field on it.

When i add my frames to a TScrollBox
code

if (FOrders)
{
int i = 0;
while (i < FOrders->Size )
{
clsOrder *lcurOrder = FOrders->GetOrderAtPos(i++);
TFrameOrderRow * lcurItem = new TFrameOrderRow(scbOrderItems,
lcurOrder,Mediator);
lcurItem->Parent = scbOrderItems;
lcurItem->Name += "00" +String(i);
lcurItem->Align = alTop;
}
}

the first time they are all correct in place and the key up and down are
working fine,

after i remove the frames and add them again

code for the remove
void __fastcall TFrameOrderList::RemoveOrderClients()
{
int l =0;
while (scbOrderItems->ComponentCount>l)
{
TComponent * lComp = scbOrderItems->Components[l];
if (dynamic_cast<TFrameOrderRow *>(lComp) != NULL)
{
TFrameOrderRow * lOrderRow;
lOrderRow = dynamic_cast<TFrameOrderRow *>(lComp);
lOrderRow->Parent = NULL;
delete lOrderRow;
}
else
{
l++;
}
}
}

I persume that in one or an other way I don't remove my frames in the
right
way.

I hope you can go on with this information.

jvdn


 

Re:Using TScrollBox Problems scrolling.

see the attachments whith title
Re: Using TScrollBox Problems scrolling.
Jochanan
"Hans Galema" < XXXX@XXXXX.COM >schreef in bericht
Quote
Jochanan wrote:

>I hope you can stil take a look at is.

>here is the code because i can't send an attachment.

Indeed you cannot add attachments in this newsgroup. But you can
in the attachments newsgroup. Please zip the project and place it in
the attachmentsgroup:
borland.public.attachments

Then I will have a look.

Hans.
 

Re:Using TScrollBox Problems scrolling.

Jochanan wrote:
Quote
see the attachments whith title
Re: Using TScrollBox Problems scrolling.
As I use bcb5 I had to make a new project as that for bcb6 is not usable.
But that was easy enough: just adding four units was all.
Had one alert : "FrameOrderList->DisignSize does not exits.
I neglected the message.
It compiled and run then straight away. Compliments.
Had to problems with the order of the list: Could click the buttons
btnClearList and btnBuildList many times. Always the same result.
The creating order is AAP,NOOT,Mies and what I get is always
-from top to bottom- Mies,NOOT,AAP.
You are unclear in statimg that you still have problems with this
or that it runs as expected. Please tell what you expect that happens.
When I use the tab key and then the arrow keys always one frame is selected.
There is a certain order then. This order is alway the same.
Please tell what the problem is. Tell how you want things to happen and
then tell what happens instead.
Hans.
 

Re:Using TScrollBox Problems scrolling.

Hans Galema wrote:
Quote
Had to problems with the order of the list: Could click the buttons
Had no problems ...
Further I don't understand that you speak about a scrolling problem.
Scrolling has to to with scrollbars and bringing objects in view.
With those arrowkeys you only change focus and or selected state
and or color.
Hans.
 

Re:Using TScrollBox Problems scrolling.

maybe My question was not clear,
when you tab unto the Scrollbox and when you enter you will see that the
last element of the list is getting selected.
that should be the first one. in code i tel Components[0] to get the focus.
at that moment i use the arrow key's and see that the sellected item changes
from the last one to the privius one that should have been the first one to
the second one.
If you generate 3 or 4 times a list. there is a very long list with AAP NOOT
MIES AAP NOOT MIES then you will see that the scrolling is reacting in a
different way than you will expect from the list arrow down is scrolling
throw the list bottum up insted of top down.
in my privius situation i created the first llist befor displaying the frame
than the first one was correct and in the refresh it changed to be upside
down.
in the example i created for you i just created it runtime so the first part
of my question dissappeard there. the list is AAP NOOT MIES but it shows
MIES, NOOT, AAP.
if you debug the list you can se that the order is AAP , NOOT, MIES.
I hope the problem is more clear by now
regards Jochanan.
"Hans Galema" < XXXX@XXXXX.COM >schreef in bericht
Quote
Hans Galema wrote:

>Had to problems with the order of the list: Could click the buttons

Had no problems ...

Further I don't understand that you speak about a scrolling problem.
Scrolling has to to with scrollbars and bringing objects in view.
With those arrowkeys you only change focus and or selected state
and or color.

Hans.
 

Re:Using TScrollBox Problems scrolling.

Hans Galema wrote:
Quote
The creating order is AAP,NOOT,Mies and what I get is always
-from top to bottom- Mies,NOOT,AAP.
Adapt the next function where you force the last added frame
to the top. This will confuse the vcl I think. Better place
every frame on a fixed place.
void __fastcall TFrameOrderList::AttachOrderClients(bool pBottomToTop)
{
.....
// lcurItem->Align = alTop;
lcurItem->Top = lcurItem->Height * ( i - 1 );
.....
Arrow keys now behave as on might expect.
This will also handle extra items ... Wim zus Jet ... <g>.
Hans.
 

Re:Using TScrollBox Problems scrolling.

thanks this seems to work
jvdn
"Hans Galema" < XXXX@XXXXX.COM >schreef in bericht
Quote
Hans Galema wrote:

>The creating order is AAP,NOOT,Mies and what I get is always
>-from top to bottom- Mies,NOOT,AAP.

Adapt the next function where you force the last added frame
to the top. This will confuse the vcl I think. Better place
every frame on a fixed place.

void __fastcall TFrameOrderList::AttachOrderClients(bool pBottomToTop)
{
.....
// lcurItem->Align = alTop;
lcurItem->Top = lcurItem->Height * ( i - 1 );
.....

Arrow keys now behave as on might expect.

This will also handle extra items ... Wim zus Jet ... <g>.

Hans.