13 / 13 / 2
Регистрация: 01.10.2008
Сообщений: 116
|
|
1
|
Проблемы с использованием 2-х Unit
16.03.2009, 19:24. Показов 1118. Ответов 1
Есть 1 форма и 2 юнита. Unit1 основной, а Unit2 добавлен. К переменным Unit1 могу обратиться только так RJW->Xback, а на прямую не получается.
Другая проблема, система начинает тормозить при вызове методов т.е в пишу RJW-> [пауза] потом появляются методы. Как убрать тормоза.
Unit1.cpp
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
| //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TRJW *RJW;
//---------------------------------------------------------------------------
__fastcall TRJW::TRJW(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TRJW::FormCreate(TObject *Sender)
{
ScrollCoef = 10;
ScrollHoriz->Max = Fon->Width-GraphBox->Width;
ScrollVert->Max = Fon->Height-GraphBox->Height;
Img->Width = Fon->Width;
Img->Height =Fon->Height;
TRect tRect(0,0,Img->Width,Img->Height);
Img->Canvas->FillRect(tRect);
LenShip = 5;
Wide = 5;
Img->Canvas->Pen->Width = Wide;
F();
}
//---------------------------------------------------------------------------
void __fastcall TRJW::ScrollVertChange(TObject *Sender)
{
Fon->Top = - ScrollVert->Position;
Img->Top = - ScrollVert->Position;
}
//---------------------------------------------------------------------------
void __fastcall TRJW::ScrollHorizChange(TObject *Sender)
{
Fon->Left = - ScrollHoriz->Position;
Img->Left = - ScrollHoriz->Position;
}
//---------------------------------------------------------------------------
void __fastcall TRJW::ImgMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
XM = X;
YM = Y;
Bar->Panels->Items[0]->Text = IntToStr(XM) + " / " + IntToStr(Img->Width);
Bar->Panels->Items[1]->Text = IntToStr(YM) + " / " + IntToStr(Img->Height);
}
//---------------------------------------------------------------------------
void __fastcall TRJW::ImgClick(TObject *Sender)
{
if (ShipSetupButton->Checked == true) Draw(XM,YM);
else
{
KursDraw(XM,YM);
Bar->Panels->Items[2]->Text = IntToStr(XBack);
Bar->Panels->Items[3]->Text = IntToStr(YBack);
}
}
//--------------------------------------------------------------------------- |
|
Unit1.h
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
| //---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <jpeg.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TRJW : public TForm
{
__published: // IDE-managed Components
TGroupBox *GraphBox;
TImage *Fon;
TScrollBar *ScrollHoriz;
TScrollBar *ScrollVert;
TImage *Img;
TStatusBar *Bar;
TCheckBox *ShipSetupButton;
void __fastcall FormCreate(TObject *Sender);
void __fastcall ScrollVertChange(TObject *Sender);
void __fastcall ScrollHorizChange(TObject *Sender);
void __fastcall ImgMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y);
void __fastcall ImgClick(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TRJW(TComponent* Owner);
int ScrollCoef;
int XM,YM;
int XBack,YBack;
int LenShip, Wide;
};
//---------------------------------------------------------------------------
extern PACKAGE TRJW *RJW;
void F();
void Draw (int x, int y);
void Clr(int x,int y);
void KursDraw (int xnow, int ynow);
//---------------------------------------------------------------------------
#endif |
|
Unit2.cpp
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
| //---------------------------------------------------------------------------
#pragma hdrstop
#include "Unit2.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
void F()
{
RJW->Img->Canvas->Pen->Width = 1;
RJW->Img->Canvas->Pen->Style = psDot;
RJW->Img->Canvas->MoveTo(50,50);
RJW->Img->Canvas->LineTo(100,100);
RJW->Img->Canvas->Rectangle(600,600,1200,1200);
}
//---
void Draw(int x, int y)
{
RJW->XBack = x;
RJW->YBack = y;
RJW->Img->Canvas->MoveTo(x-RJW->LenShip/2,y-RJW->LenShip/2);
RJW->Img->Canvas->LineTo(x+RJW->LenShip/2,y+RJW->LenShip/2);
}
//---
void Clr(int x,int y)
{
RJW->Img->Canvas->Pen->Mode = pmNotXor;
RJW->Img->Canvas->MoveTo(x-RJW->LenShip/2,y-RJW->LenShip/2);
RJW->Img->Canvas->LineTo(x+RJW->LenShip/2,y+RJW->LenShip/2);
}
//void KursDraw (int xnow, int ynow, int xback, int yback)
void KursDraw (int xnow, int ynow)
{
RJW->Img->Canvas->Pen->Style = psDot;
RJW->Img->Canvas->Pen->Width = 1;
RJW->Img->Canvas->MoveTo(RJW->XBack,RJW->YBack);
RJW->Img->Canvas->LineTo(xnow,ynow);
RJW->Img->Canvas->Pen->Style = psSolid;
RJW->Img->Canvas->Pen->Width = RJW->Wide;
Draw (xnow, ynow);
} |
|
0
|