BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TList problems

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Michele Santucci
Guest





PostPosted: Wed Apr 21, 2004 3:30 pm    Post subject: TList problems Reply with quote



Someone can tell me why this piece of code don't work?
The problem is in the creation of new areas and their drawing (case
psTracingArea of mpAreaClick method and mpAreaAfterTrackingLayerDraw) in the
psTracingArea block u can se I create an object TArea and insert it in a
TList object then I try to retrieve the inserted object from the list but it
seems to be inconsistent (but I have no runtime errors).

Area.h

//--------------------------------------------------------------------------
-

#ifndef AreaH
#define AreaH
//--------------------------------------------------------------------------
-
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ActnList.hpp>
#include <ComCtrls.hpp>
#include <Menus.hpp>

#include "MapObjects2_OCX.h"
#include "MapObjects2_TLB.h"

#include "Coordinate.h"
#include "ScosemProfile.h"
#include "AreaProperties.h"

#include <OleCtrls.hpp>
#include <ToolWin.hpp>
//--------------------------------------------------------------------------
-
typedef class Area
{
public:
AnsiString asArea;
IMoRectanglePtr Shape;
ColorConstants ccWatermark;
} TArea;

typedef TArea* TAreaPtr;
//--------------------------------------------------------------------------
-
class TfrmArea : public TForm
{
__published: // IDE-managed Components
TMainMenu *mmArea;
TStatusBar *sbArea;
TMenuItem *miFile;
TMenuItem *miExit;
TCoolBar *cbArea;
TPageControl *pcItems;
TTabSheet *tsItems;
TTreeView *tvItems;
TPageControl *pcMap;
TTabSheet *tsMap;
TMap *mpArea;
TActionList *alAreaActions;
TAction *aNewArea;
TAction *aExit;
TAction *aZoomIn;
TAction *aZoomOut;
TAction *aReset;
TAction *aZoomArea;
TAction *aPan;
TAction *aEditArea;
TPopupMenu *pmMap;
TMenuItem *miArea;
TMenuItem *miNewArea;
TMenuItem *miDeleteArea;
TMenuItem *N4;
TMenuItem *miZoomIn;
TMenuItem *miZoomOut;
TMenuItem *miZoomArea;
TMenuItem *miPan;
TMenuItem *miReset;
TMenuItem *N5;
TMenuItem *miProperties;
void __fastcall aExitExecute(TObject *Sender);
void __fastcall mpAreaMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y);
void __fastcall FormCreate(TObject *Sender);
void __fastcall aNewAreaExecute(TObject *Sender);
void __fastcall mpAreaClick(TObject *Sender);
void __fastcall mpAreaAfterTrackingLayerDraw(TObject *Sender,
OLE_HANDLE hDC);
void __fastcall aZoomInExecute(TObject *Sender);
void __fastcall aZoomOutExecute(TObject *Sender);
void __fastcall aZoomAreaExecute(TObject *Sender);
void __fastcall aResetExecute(TObject *Sender);
void __fastcall aPanExecute(TObject *Sender);
void __fastcall aEditAreaExecute(TObject *Sender);
private: // User declarations
TList* lstAreas;

ProfileStatus psProfileMode;
public: // User declarations
__fastcall TfrmArea(TComponent* Owner);
};
//--------------------------------------------------------------------------
-
extern PACKAGE TfrmArea *frmArea;
//--------------------------------------------------------------------------
-
#endif



Area.cpp



//--------------------------------------------------------------------------
-

#include <vcl.h>
#pragma hdrstop

#include "Area.h"
//--------------------------------------------------------------------------
-
#pragma package(smart_init)
#pragma link "MapObjects2_OCX"
#pragma resource "*.dfm"
TfrmArea *frmArea;
//--------------------------------------------------------------------------
-
__fastcall TfrmArea::TfrmArea(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmArea::aExitExecute(TObject *Sender)
{
Application->Terminate();
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmArea::mpAreaMouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
IMoPointPtr currentPoint;

AnsiString asLongitude,
asLatitude;


currentPoint = mpArea->ToMapPoint( X,Y );


asLatitude = Coordinate2String( double( currentPoint->X ),
cLatitude );
asLongitude = Coordinate2String( double( currentPoint->Y ),
cLongitude );

sbArea->Panels->Items[0]->Text = LATITUDE + asLatitude;
sbArea->Panels->Items[1]->Text = LONGITUDE + asLongitude;

sbArea->Panels->Items[3]->Text = AnsiString( "Items: " ) +
AnsiString( lstAreas->Count ) + AnsiString( "/" ) + AnsiString(
lstAreas->Capacity ) ;
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmArea::mpAreaClick(TObject *Sender)
{
static bool bProcessEvent = true;


if(!bProcessEvent)
return;

switch(psProfileMode)
{
case psZoomingArea:
mpArea->Extent = mpArea->TrackRectangle();
mpArea->MousePointer = moDefault;

psProfileMode = psIdle;
break;
case psPanningMap:
Application->ProcessMessages();

if( miPan->Checked )
mpArea->Pan();

mpArea->MousePointer = moDefault;

psProfileMode = psIdle;
break;
case psTracingArea:
{
IMoRectanglePtr newRectangle =
mpArea->TrackRectangle();
IMoPointPtr currentPoint;
IMoLinePtr newLeg;

AnsiString asLongitude,
asLatitude,
asTopLatitude,
asTopLongitude,
asBottomLatitude,
asBottomLongitude;

TArea* newArea = new TArea;


if( newArea==NULL )
throw Exception( AnsiString("Cannot create
area object!") );

newArea->Shape = newRectangle;

frmAreaProperties = new TfrmAreaProperties( this,
newArea );

frmAreaProperties->ShowModal();

lstAreas->Add( newArea );

lstAreas->Pack();

mpArea->MousePointer = moDefault;

psProfileMode = psIdle;
}
break;
}
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmArea::aZoomInExecute(TObject *Sender)
{
IMoRectanglePtr zoomRect = mpArea->Extent;

zoomRect->ScaleRectangle( ZOOMIN_FACTOR );
mpArea->Extent = zoomRect;
// psProfileMode = psZoomingIn;
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmArea::aZoomOutExecute(TObject *Sender)
{
IMoRectanglePtr zoomRect=mpArea->Extent;

zoomRect->ScaleRectangle( ZOOMOUT_FACTOR );
mpArea->Extent = zoomRect;
// psProfileMode = psZoomingOut;
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmArea::aResetExecute(TObject *Sender)
{
IMoRectanglePtr fullExt = mpArea->FullExtent;

mpArea->Extent = fullExt;
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmArea::aZoomAreaExecute(TObject *Sender)
{
mpArea->MousePointer = moZoom;
psProfileMode = psZoomingArea;
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmArea::aPanExecute(TObject *Sender)
{
if(!miPan->Checked)
{
miPan->Checked = true;
mpArea->MousePointer = moPanning;
psProfileMode = psPanningMap;
}
else
{
miPan->Checked = false;
mpArea->MousePointer = moDefault;
psProfileMode = psIdle;
}
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmArea::aEditAreaExecute(TObject *Sender)
{
/*
frmAreaProperties = new TfrmAreaProperties(this);
frmAreaProperties->Show();
*/
}
//--------------------------------------------------------------------------
-
void __fastcall TfrmArea::mpAreaAfterTrackingLayerDraw(TObject *Sender,
OLE_HANDLE hDC)
{
TAreaPtr currentArea;
IMoRectanglePtr trackShape;
IMoSymbolPtr trackSymbol = (IDispatch*)CreateOleObject(
"MapObjects2.Symbol" );
IMoTextSymbolPtr trackTextSymbol = (IDispatch*)CreateOleObject(
"MapObjects2.TextSymbol" );
int i;


// Draw Areas
trackSymbol->SymbolType = moFillSymbol;
trackSymbol->Style = moUpwardDiagonalFill;
trackTextSymbol->HorizontalAlignment = moAlignLeft;
trackTextSymbol->VerticalAlignment = moAlignCenter;
trackTextSymbol->Color = moBlack;

for ( i = 0 ; i < ( lstAreas->Count ) ; i++ )
{
currentArea = ( TAreaPtr )lstAreas->Items[i];

trackSymbol->Color = currentArea->ccWatermark;
trackSymbol->OutlineColor = currentArea->ccWatermark;
trackShape = currentArea->Shape;

mpArea->DrawShape( trackShape , trackSymbol );
mpArea->DrawTextA( WideString( currentArea->asArea ),
trackShape, trackTextSymbol );
}
}
//--------------------------------------------------------------------------
-

void __fastcall TfrmArea::FormCreate(TObject *Sender)
{
psProfileMode = psIdle;
lstAreas = new TList;
}
//--------------------------------------------------------------------------
-

void __fastcall TfrmArea::aNewAreaExecute(TObject *Sender)
{
mpArea->MousePointer = moCross;
psProfileMode = psTracingArea;
}
//--------------------------------------------------------------------------


--
Michele Santucci
================================
Software Development Manager
Celin Avio S.r.l.
----------------------------------------------------------------
Via Fontevivo, 21/M 19100 La Spezia
tel. +390187564080
================================


Back to top
Timothy H. Buchman
Guest





PostPosted: Wed Apr 21, 2004 5:00 pm    Post subject: Re: TList problems Reply with quote




Michele Santucci <michele.santucci> wrote

Quote:
Someone can tell me why this piece of code don't work?

void __fastcall TfrmArea::FormCreate(TObject *Sender)
{
psProfileMode = psIdle;
lstAreas = new TList;
}

The OnCreate event is considered unreliable in BCB. I suggest you
move this code to the constructor of the form and see if things are
any better. Note that this code, as quoted, is also a memory leak.
You don't delete the TList, as far as I can see. Note that list items
also have to be individually deleted.

Also, see TList in:
http://www.bcbdev.com/articles/suggest.htm

and if you really have time,
http://www.bcbdev.com/articles/list.htm
--
Timothy H. Buchman
========================================
City Center Theater, New York NY
mail address tbuchmanPLEASE(at sign)REMOVEcitycenter.org
Search .borland message archive on http://www.tamaracka.com/search.htm


Back to top
Michele Santucci
Guest





PostPosted: Thu Apr 22, 2004 10:28 am    Post subject: Re: TList problems Reply with quote



Tthnx Tim!

but the real problem was inside another part of code... anyway I fixed up
something else following your suggestions and now anything works!

"Timothy H. Buchman" <tbuchmanPLEASE(at sign)REMOVEcitycenter.org> ha
scritto nel messaggio news:4086a8c6$1 (AT) newsgroups (DOT) borland.com...
Quote:

Michele Santucci <michele.santucci> wrote in message
news:408693f4 (AT) newsgroups (DOT) borland.com...
Someone can tell me why this piece of code don't work?

void __fastcall TfrmArea::FormCreate(TObject *Sender)
{
psProfileMode = psIdle;
lstAreas = new TList;
}

The OnCreate event is considered unreliable in BCB. I suggest you
move this code to the constructor of the form and see if things are
any better. Note that this code, as quoted, is also a memory leak.
You don't delete the TList, as far as I can see. Note that list items
also have to be individually deleted.

Also, see TList in:
http://www.bcbdev.com/articles/suggest.htm

and if you really have time,
http://www.bcbdev.com/articles/list.htm
--
Timothy H. Buchman
========================================
City Center Theater, New York NY
mail address tbuchmanPLEASE(at sign)REMOVEcitycenter.org
Search .borland message archive on http://www.tamaracka.com/search.htm




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.