Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 15.06.2010, 17:05   #1
Koby
 
Регистрация: 02.06.2010
Сообщений: 7
По умолчанию Классы в delpi

Здравствуйте, написал такую программу, при нажатиина рабочую площадь сохраняются координаты в стек, затем нажимается одна из трех кнопок по названиями "Круг" "Треугольник" "Четырехугольник" и по этим координатам строится соответсвующая фигура..так для треугольника мы должны нажать на площадь 3 раза. И в обратном направлении сначало нажимаем на кнопки фигур, запоминаем их порядок в стеком, и выводим их на рабочую плоскость после произвольного кликания по нашему канвасу-например image.
вот код самой программы, помогите переделать её под классы, то есть полностью на классы(я с делфи работаю не давно как и в принципе с ООП, поэтому возникли такие трудности)
Koby вне форума Ответить с цитированием
Старый 15.06.2010, 17:09   #2
megachuhancer
Форумчанин
 
Регистрация: 16.04.2009
Сообщений: 247
По умолчанию

А где, собственно, код?
megachuhancer вне форума Ответить с цитированием
Старый 15.06.2010, 17:12   #3
Koby
 
Регистрация: 02.06.2010
Сообщений: 7
По умолчанию

<code>
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,contnrs;

type
TForm1 = class(TForm)
Shape1: TShape;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Button1: TButton;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Button2: TButton;
Button3: TButton;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
ListBox1: TListBox;
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

TMain = class(TObject)
public
AddFigure: Boolean;
end;

TCircle = class(TObject)
private
Xc: Integer;
Yc: Integer;
Pen: String;
XValue,X1Value: integer;
YValue,Y1Value: integer;
XPointer: pstring;
YPointer: pstring;
Radiys,xx,yy,rad,xx2,yy2: real;
xx1,yy1,radiys1,xx3,yy3: integer;
protected
//
public
//
// constructor AddCircle(XValue: integer; X1Value: integer;YValue,Y1Value: integer;
//XPointer: pstring;
//YPointer: pstring;
//Radiys,xx,yy,rad,xx2,yy2: real;
// xx1,yy1,radiys1,xx3,yy3: integer);

//overload;

// constructor Create; overload;
constructor Create(Xc: Integer; Yc: Integer); overload;
constructor AddCreate(XValue,X1Value: integer;
YValue,Y1Value: integer); overload;
published
property cX : Integer
read Xc;
property cY : Integer
read Yc;
// property ValueX : Integer
// read XValue;
// property ValueY : Integer
// read YValue;
// property ValueX1 : Integer
// read X1Value;
// property ValueY1 : Integer
// read Y1Value;
// property PointerX: pstring
// read XPointer;
// property PointerY: pstring
// read YPointer;
// property Rads: real
// read Radiys;
// property xxxx : real
// read xx;
// property xxxx1 : Integer
// read xx1;
// property yyyy1 : Integer
// read yy1;
// property xxxxx1 : Integer
// read xx3;
// property yyyyy1 : Integer
// read yy3;
// property Rads1 : Integer
// read Radiys1;
// property yyyy : real
//read yy;
//property newrad : real
// read rad;
end;
var
Form1: TForm1;
circle: TCircle;
XValue,X1Value: integer;
YValue,Y1Value: integer;
XPointer: pstring;
YPointer: pstring;
FigurePointer: pstring;
CirclePointer,FigureValue, TriplePointer,RecPointer,FigureValu eCircle,FigureValueTriple,
FigureValueRec: integer;
CoorXStack: TStack;
CoorYStack: TStack;
FigureStack: TStack;
Radiys,xx,yy,rad,xx2,yy2: real;
xx1,yy1,radiys1,xx3,yy3,TripleXValu e,TripleYValue,RecXValue,RecYValue: integer;
implementation

{$R *.dfm}
//constructor TCircle.Create(XCoordinate: Integer; YCoordinate: Integer);
//begin
//TCircle.XC
//end;
constructor TCircle.Create(Xc: Integer; Yc: Integer);
begin
self.Xc:=Xc;
self.Yc:=Yc;

end;

constructor TCircle.AddCreate(XValue,X1Value: integer;
YValue,Y1Value: integer);
begin
self.XValue :=XValue;
self.X1Value :=X1Value;
self.YValue :=YValue;
self.Y1Value :=Y1Value;
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
image1.Canvas.Ellipse(x-4,y-4,x+4,y+4);
circle:=TCircle.Create(X,Y);
label1.Caption :=inttostr(circle.cX);
label2.Caption :=inttostr(circle.cY);
CoorXStack.Push(Pstring(x));
CoorYStack.Push(Pstring(y));
label9.Caption:=inttostr(CoorXStack .count);
label12.Caption :=inttostr(FigureStack.Count);


</code>
Koby вне форума Ответить с цитированием
Старый 15.06.2010, 17:13   #4
Koby
 
Регистрация: 02.06.2010
Сообщений: 7
По умолчанию

продолжение:
if CoorXStack.count=4 then
begin
if FigureStack.count>0 then
begin
FigurePointer:=FigureStack.peek();
if integer(FigurePointer)=RecPointer then
begin
FigurePointer:=FigureStack.pop();
listbox1.Items.Delete(listbox1.Coun t-1);
FigureValueRec:=integer(FigurePoint er);
XPointer:=CoorXStack.pop();
XValue:=integer(XPointer);
label5.Caption :=inttostr(XValue);
XPointer:=CoorXStack.pop();
X1Value:=integer(XPointer);
YPointer:=CoorYStack.pop();
YValue:=integer(YPointer);
YPointer:=CoorYStack.pop();
Y1Value:=integer(YPointer);
XPointer:=CoorXStack.pop();
TripleXValue:=integer(XPointer);
YPointer:=CoorYStack.Pop();
TripleYValue:=integer(YPointer);
XPointer:=CoorXStack.pop();
RecXValue:=integer(XPointer);
YPointer:=CoorYStack.Pop();
RecYValue:=integer(YPointer);
image1.Canvas.MoveTo(XValue,YValue) ;
image1.Canvas.LineTo(X1Value,Y1Valu e);
image1.Canvas.LineTo(TripleXValue,T ripleYValue);
image1.Canvas.LineTo(RecXValue,RecY Value);
image1.Canvas.LineTo(XValue,YValue) ;
if FigureStack.count=0 then
begin
figurevaluerec:=0;
label12.Caption :=inttostr(FigureStack.Count);
end
else
label12.Caption :=inttostr(FigureStack.Count);
end;
end;
end;

if CoorXStack.count=3 then
begin
if FigureStack.count>0 then
begin
FigurePointer:=FigureStack.peek();
if integer(FigurePointer)=TriplePointe r then
begin
FigurePointer:=FigureStack.pop();
listbox1.Items.Delete(listbox1.Coun t-1);
FigureValueTriple:=integer(FigurePo inter);
XPointer:=CoorXStack.pop();
XValue:=integer(XPointer);
label5.Caption :=inttostr(XValue);
XPointer:=CoorXStack.pop();
X1Value:=integer(XPointer);
YPointer:=CoorYStack.pop();
YValue:=integer(YPointer);
YPointer:=CoorYStack.pop();
Y1Value:=integer(YPointer);
XPointer:=CoorXStack.pop();
TripleXValue:=integer(XPointer);
YPointer:=CoorYStack.Pop();
TripleYValue:=integer(YPointer);
label12.Caption :=inttostr(FigureStack.Count);
image1.Canvas.MoveTo(XValue,YValue) ;
image1.Canvas.LineTo(X1Value,Y1Valu e);
image1.Canvas.LineTo(TripleXValue,T ripleYValue);
image1.Canvas.LineTo(XValue,YValue) ;
if FigureStack.count=0 then
begin
figurevaluetriple:=0;
label12.Caption :=inttostr(FigureStack.Count);
end
else
label12.Caption :=inttostr(FigureStack.Count);
end;
end;
end;

if CoorXStack.count=2 then
begin
if FigureStack.count>0 then
begin
FigurePointer:=FigureStack.peek();
if integer(FigurePointer)=CirclePointe r then
begin
FigurePointer:=FigureStack.pop();
listbox1.Items.Delete(listbox1.Coun t-1);
FigureValuecircle:=integer(FigurePo inter);
XPointer:=CoorXStack.pop();
Circle.XValue:=integer(XPointer);
label5.Caption :=inttostr(XValue);
XPointer:=CoorXStack.pop();
Circle.X1Value:=integer(XPointer);
YPointer:=CoorYStack.pop();
Circle.YValue:=integer(YPointer);
YPointer:=CoorYStack.pop();
Circle.Y1Value:=integer(YPointer);
Radiys:= sqrt(((Circle.X1Value-Circle.XValue)*(Circle.X1Value-Circle.XValue))+((Circle.Y1Value-Circle.YValue)*(Circle.Y1Value-Circle.YValue)));
rad:=sqrt(radiys*radiys);
Radiys1:=round(Radiys);
xx:=Circle.XValue-rad;
yy:=Circle.YValue-rad;
xx1:=round(xx);
yy1:=round(yy);
xx2:=Circle.XValue+rad;
yy2:=Circle.YValue+rad;
xx3:=round(xx2);
yy3:=round(yy2);
image1.Canvas.Ellipse(xx1,yy1,xx3,y y3);
if FigureStack.count=0 then
begin
figurevaluecircle:=0;
label12.Caption :=inttostr(FigureStack.Count);
end
else
begin

label12.Caption :=inttostr(FigureStack.Count);

end;
label12.Caption :=inttostr(FigureStack.Count);
end;
end;
end;
end;
Koby вне форума Ответить с цитированием
Старый 15.06.2010, 17:13   #5
Koby
 
Регистрация: 02.06.2010
Сообщений: 7
По умолчанию

и ещё
procedure TForm1.FormCreate(Sender: TObject);
begin
CoorXStack:=TStack.Create;
CoorYStack:=TStack.Create;
FigureStack:=TStack.Create;
CirclePointer:=2;
TriplePointer:=3;
RecPointer:=4;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if coorXStack.Count<=1 then
begin
FigureStack.Push(Pstring(CirclePoin ter));
listbox1.Items.Add(inttostr(Circlep ointer));
label12.Caption :=inttostr(FigureStack.Count);
//FigurePointer:=FigureStack.peek();
//FigureValueCircle:=integer(FigurePo inter);
end;
if CoorXStack.Count>=2 then
begin
XPointer:=CoorXStack.pop();
Circle.XValue:=integer(XPointer);
label5.Caption :=inttostr(XValue);
XPointer:=CoorXStack.pop();
Circle.X1Value:=integer(XPointer);
YPointer:=CoorYStack.pop();
Circle.YValue:=integer(YPointer);
YPointer:=CoorYStack.pop();
Circle.Y1Value:=integer(YPointer);
Radiys:= sqrt(((Circle.X1Value-Circle.XValue)*(Circle.X1Value-Circle.XValue))+((Circle.Y1Value-Circle.YValue)*(Circle.Y1Value-Circle.YValue)));
rad:=sqrt(radiys*radiys);
Radiys1:=round(Radiys);
xx:=Circle.XValue-rad;
yy:=Circle.YValue-rad;
xx1:=round(xx);
yy1:=round(yy);
xx2:=Circle.XValue+rad;
yy2:=Circle.YValue+rad;
xx3:=round(xx2);
yy3:=round(yy2);
image1.Canvas.Ellipse(xx1,yy1,xx3,y y3);
label12.Caption :=inttostr(FigureStack.Count);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
if coorXStack.Count<=2 then
begin
ShowMessage('ûûûûûû');
FigureStack.Push(Pstring(TriplePoin ter));
listbox1.Items.Add(inttostr(Triplep ointer));
label12.Caption :=inttostr(FigureStack.Count);
//FigurePointer:=FigureStack.peek();
//FigureValueTriple:=integer(FigurePo inter);
end;
if CoorXStack.Count>=3 then
begin
ShowMessage('lolool');
XPointer:=CoorXStack.pop();
XValue:=integer(XPointer);
label6.Caption :=inttostr(XValue);
XPointer:=CoorXStack.pop();
X1Value:=integer(XPointer);
YPointer:=CoorYStack.pop();
YValue:=integer(YPointer);
YPointer:=CoorYStack.pop();
Y1Value:=integer(YPointer);
XPointer:=CoorXStack.pop();
TripleXValue:=integer(XPointer);
YPointer:=CoorYStack.Pop();
TripleYValue:=integer(YPointer);
image1.Canvas.MoveTo(XValue,YValue) ;
image1.Canvas.LineTo(X1Value,Y1Valu e);
image1.Canvas.LineTo(TripleXValue,T ripleYValue);
image1.Canvas.LineTo(XValue,YValue) ;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if coorXStack.Count<=3 then
begin
FigureStack.Push(Pstring(RecPointer ));
listbox1.Items.Add(inttostr(Recpoin ter));
label12.Caption :=inttostr(FigureStack.Count);
FigurePointer:=FigureStack.peek();
FigureValueRec:=integer(FigurePoint er);
end;
if CoorXStack.Count>=4 then
begin
XPointer:=CoorXStack.pop();
XValue:=integer(XPointer);
XPointer:=CoorXStack.pop();
X1Value:=integer(XPointer);
YPointer:=CoorYStack.pop();
YValue:=integer(YPointer);
YPointer:=CoorYStack.pop();
Y1Value:=integer(YPointer);
XPointer:=CoorXStack.pop();
TripleXValue:=integer(XPointer);
YPointer:=CoorYStack.Pop();
TripleYValue:=integer(YPointer);
XPointer:=CoorXStack.pop();
RecXValue:=integer(XPointer);
YPointer:=CoorYStack.Pop();
RecYValue:=integer(YPointer);
image1.Canvas.MoveTo(XValue,YValue) ;
image1.Canvas.LineTo(X1Value,Y1Valu e);
image1.Canvas.LineTo(TripleXValue,T ripleYValue);
image1.Canvas.LineTo(RecXValue,RecY Value);
image1.Canvas.LineTo(XValue,YValue) ;
end;
end;

end.
Koby вне форума Ответить с цитированием
Старый 15.06.2010, 17:19   #6
Koby
 
Регистрация: 02.06.2010
Сообщений: 7
По умолчанию

вот сама прога
Вложения
Тип файла: rar file.rar (2.2 Кб, 8 просмотров)
Koby вне форума Ответить с цитированием
Старый 15.06.2010, 21:39   #7
Koby
 
Регистрация: 02.06.2010
Сообщений: 7
По умолчанию

помогите кто ниб
Koby вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Delpi-перекодировка Бурундук Помощь студентам 9 21.08.2010 13:27
Составить программу для вычисления значений функции в Delpi Queen Помощь студентам 5 30.05.2010 20:13
Шифрование на Delpi , Pascal, C!!! EnergyNat Помощь студентам 1 01.03.2010 18:00
создание БД Access в Delpi и проблема!!! bmb_66 БД в Delphi 4 02.01.2008 10:48